2014-10-11 118 views
0

我正在盡我所能打開我的網站上的SSL。不過,我對nginx配置文件相當陌生。我下面的代碼給了我一個重定向循環。我究竟做錯了什麼?Nginx和SSL讓我重定向循環

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

server { 
    listen 443 ssl; 
    ssl on; 
    ssl_certificate /etc/ssl/www_website_com_final.crt; 
    ssl_certificate_key /etc/ssl/www_website_com.key; 

    root /var/www/website.com/htdocs/public; 
    index index.php index.html index.htm; 

    auth_basic "Restricted"; 
    auth_basic_user_file /var/www/website.com/htdocs/.htpasswd; 

    server_name www.website.com; 

    #browse folders if no index file 
    #autoindex on; 

    # serve static files directly 
    #location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { 
    # access_log off; 
    # expires max; 
    #} 

    location/{ 
     try_files $uri $uri/ /index.php?$query_string; 
    } 

    location ~ \.php$ { 
     try_files $uri /index.php =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 
+0

ServerFault上應該詢問服務器配置問題,而不是StackOverflow。 – 2014-10-11 10:31:58

回答

0

您在conf文件中有不同的服務器名稱。你在做的是從端口80將請求重定向到端口443上的「server.com」的$ server_name。但是,在端口443上,您的server_name是www.website.com。您也可以在您的http服務器塊中使用通配符服務器名稱,例如「* .website.com」。

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

server { 
    listen 443; 
    server_name www.website.com; # this needs to be changed to website.com. 
    ...... 
} 
0

如果有人有帶環重定向和SSL

一個問題,你必須在所有網頁上啓用SSL和SSL力

後臺>首選項>常規;-)