NGINX - CORS 错误仅影响 Firefox

NGINX - CORS 错误仅影响 Firefox

这是 Nginx 的问题,仅影响 Firefox。我有以下配置: http://pastebin.com/q6Yeqxv9

upstream connect {
        server 127.0.0.1:8080;
}

server {
        server_name admin.example.com www.admin.example.com;
        listen 80;
        return 301 https://admin.example.com$request_uri;
}

server {
        listen 80;
        server_name ankieta.example.com www.ankieta.example.com;
        add_header Access-Control-Allow-Origin $http_origin;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, PATCH, DELETE';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Headers' 'Access-Control-Request-Method,Access-Control-Request-Headers,Cache,Pragma,Authorization,Accept,Accept-Encoding,Accept-Language,Host,Referer,Content-Length,Origin,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
        return 301 https://ankieta.example.com$request_uri;
}

server {
        server_name admin.example.com;
        listen 443 ssl;
        ssl_certificate /srv/ssl/14182263.pem;
        ssl_certificate_key /srv/ssl/admin_i_ankieta.example.com.key;

        ssl_protocols SSLv3 TLSv1;
        ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;

        location / {
                proxy_pass http://connect;
        }
}

server {
        server_name ankieta.example.com;
        listen 443 ssl;
        ssl_certificate /srv/ssl/14182263.pem;
        ssl_certificate_key /srv/ssl/admin_i_ankieta.example.com.key;

        ssl_protocols SSLv3 TLSv1;
        ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;

        root /srv/limesurvey;
        index index.php;

        add_header 'Access-Control-Allow-Origin' $http_origin;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, PATCH, DELETE';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Headers' 'Access-Control-Request-Method,Access-Control-Request-Headers,Cache,Pragma,Authorization,Accept,Accept-Encoding,Accept-Language,Host,Referer,Content-Length,Origin,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

        client_max_body_size 4M;

        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        location ~ /*.php$ {

                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME /srv/limesurvey$fastcgi_script_name;
#                       fastcgi_param HTTPS $https;
                fastcgi_intercept_errors on;
                fastcgi_pass 127.0.0.1:9000;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }


}

这基本上是一个 AngularJS 应用程序和一个 PHP 应用程序 (LimeSurvey),由同一个 Web 服务器 (Nginx) 在两个不同的域下提供服务。AngularJS 实际上由 ConnectJS 提供服务,而 ConnectJS 由 Nginx 代理(ConnectJS 仅在本地主机上监听)。

在 Firefox 控制台中我得到了这个:

跨源请求被阻止:同源策略不允许读取远程资源 https://ankieta.example.com/admin/remotecontrol。可以通过将资源移动到同一个域或启用 CORS 来解决此问题。

这当然很烦人。其他浏览器运行良好(Chrome、IE)。

对此有什么建议吗?

答案1

问题发生的原因是 Firefox 没有授权 API 的 SSL 证书。通过使用 Firefox 导航到端点来信任站点的证书可以暂时解决问题,但更改证书则可以永久解决问题。

Firefox 和 LimeSurvey 远程控制 API 的标头问题可以通过代理固定标头值或发送 blob 来修复,具体如下:https://stackoverflow.com/questions/24465304/trouble-changing-request-headers-in-firefox-with-angularjs

相关内容