【问题标题】:NGINX infinite loop when I try to redirect http to https当我尝试将 http 重定向到 https 时,NGINX 无限循环
【发布时间】:2015-12-22 05:55:30
【问题描述】:

我正在将我的整个网站从 http 移动到 https 由于我有几个域,我需要重定向到我网站的 https 版本。

问题是当我尝试将原始域从http重定向到https时,nginx给了我一个无限循环。

你们能帮帮我吗?

这是我的配置

server {
    listen       80;
    server_name  www.domain.com.br domain.com.br w.domain.com.br  ww.domain.com.br wwww.domain.com.br domain1.com.br www.domain1.com.br domain.com www.domain.com domain.net.br www.domain.net.br;
    return 301 https://www.domain.com.br$request_uri;
}

server {
    listen       443;
    server_name  domain.com.br w.domain.com.br  ww.domain.com.br wwww.domain.com.br domain1.com.br www.domain1.com.br domain.com www.domain.com domain.net.br www.domain.net.br;
    ssl                  on;
    ssl_certificate      /home/ssl/ssl-bundle.crt;
    ssl_certificate_key  /home/ssl/myserver.key;
    return 301 https://www.domain.com.br$request_uri;
}

server {
    listen       443;
    ssl                  on;
    ssl_certificate      /home/ssl/ssl-bundle.crt;
    ssl_certificate_key  /home/ssl/myserver.key;
    #ssl_session_timeout  5m;
    #ssl_protocols  SSLv2 SSLv3 TLSv1;
    server_name  www.domain.com.br;
    root   /usr/share/nginx/html2;


    location / {   
        index  index.php;
        if ($request_filename !~* \.(php|gif|html|jpe?g|png|ico|js|css|flv|swf|pdf|xml)$ ) { rewrite ^ /index.php; }
    }

    location ~ \.php$ {        
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.socket;
        fastcgi_index  index.php;
        # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

【问题讨论】:

    标签: ssl nginx https


    【解决方案1】:

    第二个服务器条目正在创建无限循环。它包括在 https(443) 端口上向同一站点返回 301

    为子域重定向尝试这个答案: https://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while-maintaining-sub-dom

    【讨论】:

    • 我不明白为什么第二个正在创建无限循环第二个服务器条目与地址不匹配:www.domain.com.br 只有第三个。我错了吗?
    • 因为您要重定向到的服务器名称在“服务器名称”中
    • 你也是先列出“catch all”。
    • 你的意思是这个server_name domain.com.br 捕获了像www.domain.com.br 这样的每个子域吗?
    猜你喜欢
    • 1970-01-01
    • 2011-12-05
    • 2019-08-13
    • 2019-06-16
    • 1970-01-01
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    相关资源
    最近更新 更多