Nginx 跨域及代理配置跨域
无需要废话,直接上代码
server {
charset utf-8;
client_max_body_size 512M;
listen 52000;
server_name 192.168.100.100;
index index.html index.htm;
try_files $uri $uri/ /index.html;
root /home/wwwroot/vue_html/hxmall_java_h5;
add_header Strict-Transport-Security "max-age=31536000";
add_header Cache-Control no-cache;
add_header X-Cache $upstream_cache_status;
error_page 497 https://$host$request_uri;
#跨域
location / {
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Allow-Methods '*';
add_header Access-Control-Allow-Credentials 'true';
return 204;
}
if ($request_method != 'OPTIONS') {
add_header Access-Control-Allow-Origin '*' always;
add_header Access-Control-Allow-Credentials 'true';
}
}
location ^~ /api
{
proxy_pass http://127.0.0.1:36500;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 1800s;
proxy_send_timeout 86400s;
proxy_read_timeout 86400s;
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_set_header Access-Control-Allow-Origin '*';
proxy_set_header Access-Control-Allow-Methods '*';
proxy_set_header Access-Control-Allow-Headers '*';
proxy_set_header Access-Control-Allow-Credentials 'true';
}
}
原文地址:https://blog.csdn.net/mark885/article/details/142451772
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!