美文网首页
nginx 解决Blocked a frame with ori

nginx 解决Blocked a frame with ori

作者: 日不落000 | 来源:发表于2021-03-11 16:11 被阅读0次
    • Blocked a frame with origin "http://xxxx" from accessing a cross-origin iframe.解决办法

    本地开发时访问其他服务器资源可能涉及跨域,可以使用NGINX配置相关信息(开发环境地址,代理环境地址),然后通过NGINX代理的地址和端口号访问本地开发环境,即可不跨域。

    访问地址为:http://localhost:8091

    相关配置如下:

        #server 远程服务器地址
        upstream remote {
          server 10.9.160.26 weight=5;  
        }
        server {
            listen       8091;
            server_name  localhost;
    
            #charset koi8-r;
    
            # access_log  logs/host.access.log  main;
              # 页面地址是a.com,但是要用b.com的cookie需要
            proxy_set_header Cookie $http_cookie;
            # iframe 跨域问题
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_hide_header X-Frame-Options;
            add_header X-Frame-Options ALLOWALL;
            # add_header X-Frame-Options "ALLOW-FROM http://localhost:8080";
    
            add_header Access-Control-Allow-Origin *; # 必须要有
            add_header Access-Control-Allow-Headers *; # 必须要有
            proxy_cookie_domain remote localhost;  # 重要 对应upstream remote #注意别写错位置了 proxy_cookie_path / /;
            location / {
              # root html/build;
              # index  index.html;
              proxy_pass http://localhost:8081;//本地开发环境运行在8081端口
            }
    
            #通用
            location ~ (/a1|/b2|/itsm|/alert) {
                proxy_pass http://remote;
            }
    
    
    
            #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;
            }
        }
    

    相关文章

      网友评论

          本文标题:nginx 解决Blocked a frame with ori

          本文链接:https://www.haomeiwen.com/subject/ksfoqltx.html