代码拉取完成,页面将自动刷新
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8888;
server_name localhost;
location /api/ {
#$http_origin动态获取请求客户端请求的域
# 这个必须有,否则跨域失败
add_header 'Access-Control-Allow-Origin' $http_origin;
# 可选,允许客户端的请求方法
add_header 'Access-Control-Allow-Methods' '*';
# 可选,允许客户端提交Cookie
add_header 'Access-Control-Allow-Credentials' 'true';
# 可选,允许客户端访问的响应头
add_header 'Access-Control-Allow-Headers' 'Cache-Control,Content-Language,token,level,Content-Type,Expires,Last-Modified,Pragma,api-format-tag,Authorization';
# 处理预检请求
if ($request_method = 'OPTIONS') {
# 必须有,指定允许跨域的方法,*代表所有
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' '*';
# 可选,允许客户端访问的响应头
add_header 'Access-Control-Allow-Headers' 'Cache-Control, Content-Language,token,level,Content-Type,Expires,Last-Modified,Pragma,api-format-tag,Authorization';
# 预检请求缓存时间
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
# SpringBoot 应用访问路径
proxy_pass http://localhost:39201/api/;
# proxy_pass http://localhost:10080/;
proxy_set_header Host $host:$server_port; #这一行就是来解决问题的,将NGINX接收到请求头中的Host和端口继续往下传递
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 6000;
proxy_read_timeout 6000;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。