nginx鉴权之后查看pdf报错未能加载pdf文档

nginx鉴权之后查看pdf报错未能加载pdf文档,其他浏览器正常,只有谷歌浏览器出现了该问题

nginx查看pdf时报错显示未能加载pdf文档

nginx做了鉴权后存在该问题现象,谷歌浏览器对于跨域的要求比较严格导致的

#主要是在nginx配置中加入以下跨域的配置
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

if ($request_method = 'OPTIONS') {
                                return 204;
                        }

server {
        listen       80;
        server_name  ftp.saas.XXXXX.com;
        access_log  /var/log/nginx/ftp.saas.XXXXX.com.log  main;
                default_type 'text/html';
                charset utf-8;
        #客商;
        location /traderAuthApply/ {
                        add_header Content-Type text/plain;
                        charset utf-8;
                        internal;
                        #limit_rate 200k;
                        alias /var/ftp/trader/traderAuthApply/;
                        #转由后台处理(tomcat等web容器);
                        error_page 404 =200 @backend1;
                        add_header Access-Control-Allow-Origin *;
                        add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
                        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

                        if ($request_method = 'OPTIONS') {
                                return 204;
                        }
                }
        location @backend1 {
                        rewrite ^/traderAuthApply/(.*)$                 /XX.XX.XX.ui/ftp/ftpAuth?path=$1&sso_ticket=$arg_sso_ticket&fileUrl=$scheme://$http_host$uri break;
                        proxy_pass http://XX.XX.XX.ui;
                        proxy_redirect off;
                        proxy_set_header Host $host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        add_header Access-Control-Allow-Origin *;
                        add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
                        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

                        if ($request_method = 'OPTIONS') {
                                return 204;
                        }
                        break;
                }
    }
    #客商系统;
    upstream XX.XX.XX.ui {
            server 10.0.X.X:8080 weight=8 max_fails=5 fail_timeout=10;
   }
可能与以下两个配置还有联系,以下需要注释掉
                        #add_header Content-Type text/plain;


也可能还需加入以下配置
                        proxy_set_header Cookie $http_cookie;
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值