我的网站在两个https访问中都可以使用www&非www。我还将重定向从非www更改为www,并且可以正常工作。所有访问都将重定向到https://www.example.com
但是,目前我的网站也无法重定向到www,即使使用相同的nginx默认配置。这是
server {
add_header X-Frame-Options SAMEORIGIN;
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://server_name$request_uri;}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
client_max_body_size 500M;
root /var/www/html/src/public;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* .(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location ~ .php$ {
add_header X-Frame-Options SAMEORIGIN;
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$
include fastcgi_params;
}
location ~ /.well-known {
allow all;
}
location ~ /.ht {
deny all;
}
}
我正在使用VPS Debian 8.9 x64,nginx/1.6.2
您可以尝试更新您的HTTP服务器块吗?
server {
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
请参阅https://stackoverflow.com/a/48811022/2196316 nginx conf ...