NGINX:重定向太多

时间:2017-05-01 16:18:37

标签: nginx

我在nginx代理后面托管了一个流星应用程序。我们使用https(因此301将所有http连接重定向到443)。但是,我们现在又回到了http(因此301将所有https连接重定向到80)。

当我尝试访问我的网站时,我收到错误消息,"页面未正确重定向"。但是,如果我以隐身方式访问或清除浏览器缓存和Cookie后,一切都会再次运行。

我可以更改我的nginx conf文件(下面)中的任何内容来修复此问题吗?我真的不希望所有访问者都必须清除他们的浏览数据。谢谢!

server_tokens off; # for security-by-obscurity: stop displaying nginx version

# this section is needed to proxy web-socket connections
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

# HTTP
server {    
    listen 80;
    server_name [REDACTED];

   # redirect to meteor
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade; # allow websockets
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP
    }

}

# HTTPS server
server {
    listen 443 ssl spdy; # we enable SPDY here
    server_name [REDACTED];
    root html; # irrelevant
    index index.html; # irrelevant

    # redirect to http
    return 301 http://$host$request_uri;

    ssl_certificate /etc/[REDACTED].pem;
    ssl_certificate_key /etc/[REDACTED].pem;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ciphers '[REDACTED]'
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_stapling on;
    ssl_stapling_verify on;
    add_header Strict-Transport-Security max-age=15768000;

    # If your application is not compatible with IE <= 10, this will redirect visitors to a page advising a browser update
    # This works because IE 11 does not present itself as MSIE anymore
    if ($http_user_agent ~ "MSIE" ) {
        return 303 https://browser-update.org/update.html;
    }

    location ~ /.well-known {
       allow all;
    }
}

0 个答案:

没有答案