nginx 跨域设置

匿名 (未验证) 提交于 2019-12-02 22:10:10

 

 

upstream nginx {         ip_hash;                  server 172.17.0.4:8081 weight=2;         server 172.17.0.5:8081 weight=1;          }  server {         listen       80;         server_name  www.enjoy.com;      if ( $http_origin ~ http://(.*).enjoy.com){                  set $allow_url $http_origin;         }        #是否允许请求带有验证信息          add_header Access-Control-Allow-Credentials true;          #允许跨域访问的域名,可以是一个域的列表,也可以是通配符*          add_header Access-Control-Allow-Origin  $allow_url;          #允许脚本访问的返回头          add_header Access-Control-Allow-Headers 'x-requested-with,content-type,Cache-Control,Pragma,Date,x-timestamp';          #允许使用的请求方法,以逗号隔开          add_header Access-Control-Allow-Methods 'POST,GET,OPTIONS,PUT,DELETE';          #允许自定义的头部,以逗号隔开,大小写不敏感          add_header Access-Control-Expose-Headers 'WWW-Authenticate,Server-Authorization';          #P3P支持跨域cookie操作          add_header P3P 'policyref="/w3c/p3p.xml", CP="NOI DSP PSAa OUR BUS IND ONL UNI COM NAV INT LOC"';     add_header test  1;       if ($request_method = 'OPTIONS') {              return 204;          }          location / {             root   html/static/;             index  index.html index.htm;         }      location /rout {         rewrite ^/rout/(.*)  /static/$1.html break;         root   html/;             index  index.html index.htm;         }     location /proxy {         echo "我是www.enjoy.com内容:$http_origin";     #    proxy_pass http://172.17.0.4:8081/nginx;         }     location /nginx {                 proxy_pass http://nginx;         }                  error_page   500 502 503 504  /50x.html;         location = /50x.html {             root   html;         }               }

 

转载请标明出处:nginx 跨域设置
文章来源: nginx 跨域设置
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!