Nginx的跨域配置

2022-06-01 22:02:10
2024-07-19 19:20:29

Nginx配置(这个配置,可以解决 95% 以上的跨域问题)

shell 复制代码
server {
    listen 80;
    server_name localhost 127.0.0.1;
	location / {
        add_header Access-Control-Allow-Origin $http_origin;
        add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, PATCH, DELETE, HEAD';
        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;
        }
		
		# 端口转发
		proxy_pass http://127.0.0.1:8080;
		
		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 X-Forwarded-Proto $scheme;
		
		proxy_connect_timeout 600;
		proxy_read_timeout 600;
	}
}
目录
暂无评论,欢迎留下你的评论

运营需要亿点资金维持,您的支持,是小白龙创作的动力!!!

昵称
留言
赞赏金额