2
使用Nginx / Chrome的跨源资源共享(CORS)
我有一个细分如下的网站: api.example.com developers.example.com example.com 我想同时允许example.com和developers.example.com向发出AJAX请求api.example.com。 到目前为止,我的nginx配置 api.example.com,由麒麟提供)是一个Rack应用,如下所示: upstream app_server { server unix:/tmp/api.example.com.sock fail_timeout=0; } server { listen 80; server_name api.example.com; access_log /home/nginx/api.example.com/log/access.log; error_log /home/nginx/api.example.com/log/error.log; location / { add_header 'Access-Control-Allow-Origin' 'http://example.com,http://developers.example.com'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Headers' 'Content-Type,Accept'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE'; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect …
13
nginx