Nginx做跨域范文不生效

来源:3-9 Nginx作为静态资源web服务_跨域访问场景配置

qq_善水_0

2018-08-20

Nginx做跨域访问不生效 ,没有域名 使用的是127.0.0.1访问的nginx 

配置如下:

server {

    listen       8080;

    server_name  127.0.0.1:9080;

    sendfile on;

    access_log  /var/log/nginx/host.access.log  main;

    location ~ .*\.(jpg|gif|png)$ {

        gzip on;

        gzip_http_version 1.1;

        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

        root /opt/app/code/images;

    }

    location ~ .*\.(txt|xml)$ {

        gzip on;

        gzip_http_version 1.1;

        gzip_comp_level 2;

        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript ion/x-httpd-php image/jpeg image/gif image/png;

        root /opt/app/code/doc;

    }

    location ~ ^/download {

        gzip_static on;

        tcp_nopush on;

        root /opt/app/code;

    }

    location ~ .*\.(htm|html)$ {

        expires 24h;

        root /opt/app/code;

    }

    location ~ .*\.(htm|html)$ {

        add_header 'Access-Control-Allow-Origin' $http_origin;

        add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,OPTIONS';

        root /opt/app/code;

    }

}


写回答

2回答

Jeson

2018-08-23

你好,你需要在 请求 这个地址 http://wezb.51welink.com/sync/Appjs/check_info?version=3.3&appName=weiwei 添加跨域访问规则

0
0

Jeson

2018-08-20

你好,这个问题,我想了解知道的是你的访问url是哪个?另外,查下这条请求在nginx的端的日志。如果分析不出来,将相关的截图发我吧

0
3
qq_善水_0
配置文件如下 server { listen 80; sendfile on; location ~ .*\.(jpg|gif|png)$ { gzip on; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; root /opt/app/code/images; } location ~ .*\.(txt|xml)$ { gzip on; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; root /opt/app/code/doc; } location ~ ^/download { gzip_static on; tcp_nopush on; root /opt/app/code; } location ~ .*\.(htm|html)$ { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS; if ($request_method = 'OPTIONS') { return 204; } root /opt/app/code; } }
2018-08-22
共3条回复

Nginx入门到实践-Nginx中间件应用+搭建Webserver架构

中间件、负载均衡、应用层安全防护、动静分离、Nginx+LUA开发等

4183 学习 · 908 问题

查看课程