从http到https的Nginx重定向被卡住了

时间:2015-01-16 17:14:55

标签: nginx

我正在使用Nginx,phusion_passenger在个人服务器上部署Rails应用程序。我的站点配置文件包含以下服务器块。使用此配置,我的https://192.168.1.121服务有效但我的连接并未从http://192.168.1.121重定向。我究竟做错了什么?我非常感谢任何帮助。

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        # Make site accessible from http://localhost/
        #server_name 192.168.1.121;
        server_name mydomain.com www.mydomain.com

        return 301 https://$server_name$request_uri;
}

server {
        # Make site accessible from http://localhost/
        listen 443 ssl default;

        #server_name 192.168.1.121;
        server_name mydomain.com www.mydomain.com

        # Certificate details
        ssl_certificate     /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;
        ssl_session_timeout 5m;

        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
        ssl_prefer_server_ciphers on;

        passenger_enabled on;
        rails_env production;

        root /home/deploy/www/myapplication/current/public;
        index index.html index.htm;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root html;
        }
}

1 个答案:

答案 0 :(得分:0)

对于http以及https:

,在server_name变量的末尾缺少

分号

server_name mydomain.com www.mydomain.com;