码迷,mamicode.com
首页 > 其他好文 > 详细

nginx跨域设置

时间:2017-11-22 17:51:15      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:nginx跨域设置

server {
  listen 80;
  server_name www.idc.dev;
  access_log /data/wwwlogs/www.idc.dev_nginx.log combined;
  index index.html index.htm index.php;
  root /mnt/hgfs/woker_project/www.idc.dev/wwwroot;
  
  
  location / {
     try_files $uri @apache;
     #跨域设置
            add_header Access-Control-Allow-Origin ‘*‘;
            add_header Access-Control-Allow-Methods ‘GET, POST, PUT, DELETE, OPTIONS‘;
            add_header Access-Control-Allow-Credentials ‘true‘;
            add_header Access-Control-Allow-Headers ‘Accept, Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type‘;
            if ($request_method = ‘OPTIONS‘) {
               add_header ‘Access-Control-Allow-Origin‘ ‘*‘;
               add_header ‘Access-Control-Max-Age‘ 1728000;
               add_header ‘Access-Control-Allow-Credentials‘ ‘true‘;
               add_header ‘Access-Control-Allow-Methods‘ ‘GET, POST, DELETE, PUT, OPTIONS‘;
               add_header ‘Access-Control-Allow-Headers‘ ‘Accept, Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type‘;
               add_header ‘Content-Type‘ ‘text/plain charset=UTF-8‘;
               add_header ‘Content-Length‘ 0;
               return 204;
           }
  }
  location @apache {
    proxy_pass http://127.0.0.1:88;
    include proxy.conf;
  }
  location ~ .*\.(php|php5|cgi|pl)?$ {
    proxy_pass http://127.0.0.1:88;
    include proxy.conf;
  }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /\.ht {
    deny all;
  }
}


nginx跨域设置

标签:nginx跨域设置

原文地址:http://zcdoit.blog.51cto.com/13374349/1984132

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!