weixin_33736832 2015-04-14 22:20 采纳率: 0%
浏览 93

有没有办法避免nginx中的CORS问题?

有没有办法避免nginx中的CORS问题?我的一个应用程序运行在netty-server上,它附带了使用joc.lan作为域名的Play框架,而其他应用程序是在我的应用程序中集成的php Web服务器上。我的应用程序使用iframe加载,它使用chat.joc.lan作为域名,是joc.lan的一个子域。因此,当我的应用程序中的任何人试图访问其他应用程序的任何数据时,控制台上都会遇到如下错误:

Uncaught SecurityError: Blocked a frame with origin "http://chat.joc.lan" from accessing a frame with origin "http://joc.lan". Protocols, domains, and ports must match.

我通过在两个应用程序上将document.Domain设置为主域名joc.lan来解决此错误。对于Ajax请求,我使用的是JSONP,不过它不支持火狐和IE。以下是我的主要应用程序joc.lan:

server {
    listen       80;
    server_name  joc.lan;

    location / {
        proxy_pass http://localhost:9000;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # WebSocket support (nginx 1.4)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        }
}

以下是我在joc.lan内部使用iframe的代码:

server {
                listen  80;
                server_name chat.joc.lan;
                root /opt/apps/flyhi/chat;
                index   index.php;
                # caching for images and disable access log for images
                location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|ttf|eot)$ {
                        access_log              off;
                        expires                 360d;
                }


                 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9007

location ~ \.php {
    fastcgi_pass  127.0.0.1:9011;
    fastcgi_index index.php;
    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    access_log off;
}


location / {
    try_files $uri $uri/ /index.php?r=$request_uri;

}
  • 写回答

1条回答 默认 最新

  • weixin_33749242 2015-04-15 10:11
    关注

    I am not sure but you can set the parameters in nginx config file for allowing CORS in all browsers.
    This link can be a help where there is nginx config file is given to allow CORS

    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度