军哥,关于301转跳的问题
具体情况是这样的,我绑定了 www.xxx.com 和 xxx.com 现在已经做了https, 目前www.xxx.com 和 xxx.com都可以转跳到https但是他们是分别转跳的也就是说 www.xxx.com转跳到 https://www.xxx.com; xxx.com转跳到 https://xxx.com 而不是 www.xxx.com 和 xxx.com 都转跳到https://www.xxx.com 我需要的是它们都转跳到https://www.xxx.com 请军哥解惑,我已经查了好多资料。。。下面是我的 vhost文件代码:server
{
listen 80;
#listen [::]:80;
server_name www.xxx.com xxx.com;
return 301 https://www.xxx.com$request_uri;
index index.html index.htm index.php default.html default.htm default.php;
root/home/wwwroot/56wx;
include lvse.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name www.xxx.com xxx.com;
index index.html index.htm index.php default.html default.htm default.php;
root/home/wwwroot/56wx;
ssl on;
ssl_certificate /etc/letsencrypt/live/www.xxx.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.xxx.com/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
include lvse.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
} 你前面的设置就是都跳到 https://www.xxx.com
可以把前面的 return 301 https://www.xxx.com$request_uri; 改成 return 301 https://$server_name$request_uri; 重启nginx
回复 2# 的帖子
输入 xxx.com可以转跳但是输入https://xxx.com 就不能转跳到https://www.xxx.com 了回复 3# 的帖子
最简单的方法,把https的站点配置复制一份,去掉其中www的域名,加上前面说的设置301的语句,再把带www域名https站点里的不带www的域名删掉
页:
[1]