!找了N多个小时资料终于部署成功
可以尝试去B站这个博主去学习
【springboot+vue 前后端分离部署到线上 宝塔】 https://www.bilibili.com/video/BV118411M7MX/?spm_id_from=333.1007.top_right_bar_window_history.content.click&vd_source=a0ec3b50a33add3d0d6669f2540a029d
它的资料文档地址:http://easybbs.wuhancoder.com/post/jisd64FghuZjBis
按照他的步骤完成了前后端部署,但是我的网站一直访问不到,后来我查资料改了下我的配置文件,就成功了,不知道是不是这样,分享一下。
server {
listen 6661;
server_name *.*.*.*;
location / {
alias /www/wwwroot/vue/big_event/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
# api后添加/,代理目标后面去掉api
location /api/ {
# 定义代理目标
proxy_pass http://localhost:9000/;
# 允许跨域请求
add_header Access-Control-Allow-Origin *;
# 允许带身份验证信息的跨域请求
add_header Access-Control-Allow-Credentials true;
# 允许的请求方法
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
# 允许的请求头
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
# 预检请求的有效期
add_header Access-Control-Max-Age 3600;
# 处理 OPTIONS 请求
if ($request_method = 'OPTIONS') {
add_header Content-Type 'text/plain; charset=utf-8';
add_header Content-Length 0;
return 204;
}
}
}
我也是第一次部署成功,大家自行斟酌吧(*^ —^ )!