当我尝试将http重定向到https时,NGINX无限循环

时间:2015-09-24 14:55:38

标签: ssl nginx https

我将整个网站从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;
    }
}

1 个答案:

答案 0 :(得分:0)

第二个服务器条目正在创建无限循环。它包括返回到https(443)端口

上的同一站点的301

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