我正在尽力在我的网站上启用SSL。但是,我对nginx配置文件还不熟悉。我下面的代码给了我一个重定向循环。我做错了什么?
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 :(得分:0)
您的conf文件中有不同的服务器名称。您所做的是从端口80将请求重定向到$ server_name,这是" website.com"在端口443上。但是在端口443上,您的server_name是www.website.com。您还可以使用通配符服务器名称,例如" *。website.com"在您的http服务器块中。
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. ...... }
答案 1 :(得分:0)
如果有人遇到循环重定向和SSL
的问题您必须在所有页面上启用SSL并强制使用SSL
后台>偏好>一般; - )