部署vue项目时候留个笔记,以后方便查找
server{
listen 80;
server_name web.xudakj.com; #域名
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
} #添加跨域头
root /root/article/web/dist; #文件地址
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
#下面很重要 支持跨域的
location /api{
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://xudakj:8081;
}
}