2014-10-11 55 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力

后台>首选项>常规;-)