http를 https로 리디렉션하려고 하면 NGINX 무한 루프가 발생합니다.

http를 https로 리디렉션하려고 하면 NGINX 무한 루프가 발생합니다.

전체 웹사이트를 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

server {
    listen  80 default_server;
    return  301 https://www.domain.com.br$request_uri;
}

server {
    listen  443 ssl http2   default_server;
    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;
    }
}

관련 정보