nginx跨域conf配置不起作用

server {
        listen       80;
        server_name  daidu.com;
    
    add_header 'Access-Control-Allow-Origin' *;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
    
    location /myindex {
            proxy_pass   https://xmjg.mulifang.net/WXInTerFace/myindex;
        }
        location / {
            root   www;
            index  index.html index.htm;
        }
    
    

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
阅读 1.7k
1 个回答

允许的请求方式呢?Access-Control-Allow-Methods?

# cors 测试相关
server {
    listen       80;
    server_name  cors-www.lilnong.top;
    location = /50x.html {
        root   html;
    }
    location / {
       add_header Access-Control-Allow-Origin *;
       add_header Access-Control-Max-Age 1728000;
       add_header Access-Control-Allow-Methods GET,POST,OPTIONS,PUT,DELETE;
       add_header Access-Control-Allow-Headers  'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,ACCESS-TOKEN,x-file-name';
        if ($request_method = 'OPTIONS') {
           add_header Content-Type' 'text/plain; charset=utf-8';
           add_header Content-Length 0 ;
           return 204;
        }
        proxy_pass http://www.lilnong.top;
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题