【转】vue和springboot项目使用nginx配置,并配置跨域
server {
# nginx服务器对外8081端口
listen 9527;
server_name localhost;
#charset koi8-r;
# 日志输出
#access_log logs/myvue.access.log main;
#access_log logs/host.access.log main;
# 静态文件配置
location / {
root /usr/local/vpn/dist/;
index index.html index.htm;
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;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 反向代理springboot接口服务
location /ccsrobot/ {
# 前端请求: /api/login 代理后: http://127.0.0.1:8095/login
proxy_pass http://127.0.0.1:8095/;
# 解决springboot中获取远程ip的问题
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
转自http://blog.maptoface.com/post/249
每天进步一点点,快乐生活多一点。