【问题标题】:Nginx redirects to default welcome page after https setuphttps设置后Nginx重定向到默认欢迎页面
【发布时间】:2014-09-03 07:53:03
【问题描述】:

我已经在我的 Nginx 实例上配置了 SPDY 并使用 http://spdycheck.org/ 来确认它的设置,但是由于某些奇怪的原因 Nginx 将 https 重定向到默认的 Nginx 页面,我已经从启用的站点中删除了默认符号链接,重新启动服务器,但问题仍然存在。我的站点 conf 文件有:

server {
       listen 443 spdy ssl;
       server_name foobar;
       ssl_certificate /etc/nginx/ssl/server.crt;
       ssl_certificate_key /etc/nginx/ssl/server.key;
}


server {
        listen 80;
        server_name foobar;
        return 301 https://sub.foobar.com$request_uri;
        #error_page  404         = @notfound;
        access_log /var/log/access.foobar.com.log;
        error_log /var/log/error.foobar.com.log;

        location / {
                proxy_pass http://127.0.0.1:9030;
                proxy_pass_header Server;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Scheme $scheme;
                proxy_connect_timeout 60;
                proxy_read_timeout 120;


        }
}

我需要进行哪些更改才能使其正常工作?

【问题讨论】:

标签: ssl nginx spdy


【解决方案1】:

在这个配置中很难看出你想要什么。不过可能

server {
       listen 443 spdy ssl;
       server_name foobar.com;
       ssl_certificate /etc/nginx/ssl/server.crt;
       ssl_certificate_key /etc/nginx/ssl/server.key;
        #error_page  404         = @notfound;
        access_log /var/log/access.foobar.com.log;
        error_log /var/log/error.foobar.com.log;
        location / {
                proxy_pass http://127.0.0.1:9030;
                proxy_pass_header Server;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Scheme $scheme;
                proxy_connect_timeout 60;
                proxy_read_timeout 120;


        }
}


server {
        listen 80;
        server_name foobar.com;
        return 301 https://foobar.com$request_uri;

}

此配置将所有请求从 http(80 端口)重定向到同一服务器上的 https(443 端口)。并且在 443 端口请求是后端的代理。

【讨论】:

  • 我实际上想通了,似乎我的服务器块都搞砸了,我将它们更改为看起来像您的答案并且它有效。
猜你喜欢
  • 2012-08-02
  • 2018-02-04
  • 2021-11-25
  • 2017-07-18
  • 2019-10-19
  • 1970-01-01
  • 2013-03-06
  • 2013-02-07
  • 2019-01-18
相关资源
最近更新 更多