VPS侦探论坛

标题: 军哥,关于301转跳的问题 [打印本页]

作者: a306963633    时间: 2017-12-11 09:19
标题: 军哥,关于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文件代码:
  1. server
  2.     {
  3.         listen 80;
  4.         #listen [::]:80;
  5.         server_name www.xxx.com xxx.com;
  6.                 return 301 https://www.xxx.com$request_uri;
  7.         index index.html index.htm index.php default.html default.htm default.php;
  8.         root  /home/wwwroot/56wx;

  9.         include lvse.conf;
  10.         #error_page   404   /404.html;

  11.         # Deny access to PHP files in specific directory
  12.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

  13.         include enable-php.conf;

  14.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  15.         {
  16.             expires      30d;
  17.         }

  18.         location ~ .*\.(js|css)?$
  19.         {
  20.             expires      12h;
  21.         }

  22.         location ~ /.well-known {
  23.             allow all;
  24.         }

  25.         location ~ /\.
  26.         {
  27.             deny all;
  28.         }

  29.         access_log off;
  30.     }

  31. server
  32.     {
  33.         listen 443 ssl http2;
  34.         #listen [::]:443 ssl http2;
  35.         server_name www.xxx.com xxx.com;
  36.         index index.html index.htm index.php default.html default.htm default.php;
  37.         root  /home/wwwroot/56wx;
  38.         ssl on;
  39.         ssl_certificate /etc/letsencrypt/live/www.xxx.com/fullchain.pem;
  40.         ssl_certificate_key /etc/letsencrypt/live/www.xxx.com/privkey.pem;
  41.         ssl_session_timeout 5m;
  42.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  43.         ssl_prefer_server_ciphers on;
  44.         ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
  45.         ssl_session_cache builtin:1000 shared:SSL:10m;
  46.         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  47.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

  48.         include lvse.conf;
  49.         #error_page   404   /404.html;

  50.         # Deny access to PHP files in specific directory
  51.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

  52.         include enable-php.conf;

  53.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  54.         {
  55.             expires      30d;
  56.         }

  57.         location ~ .*\.(js|css)?$
  58.         {
  59.             expires      12h;
  60.         }

  61.         location ~ /.well-known {
  62.             allow all;
  63.         }

  64.         location ~ /\.
  65.         {
  66.             deny all;
  67.         }

  68.         access_log off;
  69.     }
复制代码

作者: licess    时间: 2017-12-11 13:30
你前面的设置就是都跳到 https://www.xxx.com
可以把前面的 return 301 https://www.xxx.com$request_uri; 改成 return 301 https://$server_name$request_uri; 重启nginx
作者: a306963633    时间: 2017-12-12 08:43
标题: 回复 2# 的帖子
输入   xxx.com  可以转跳  但是  输入  https://xxx.com   就不能转跳到  https://www.xxx.com 了
作者: licess    时间: 2017-12-12 14:32
标题: 回复 3# 的帖子
最简单的方法,把https的站点配置复制一份,去掉其中www的域名,加上前面说的设置301的语句,再把带www域名https站点里的不带www的域名删掉




欢迎光临 VPS侦探论坛 (https://bbs.lnmp.com/) Powered by Discuz! X3.4