VPS侦探论坛

 找回密码
 注册
查看: 3269|回复: 3

军哥,关于301转跳的问题

[复制链接]
发表于 2017-12-11 09:19:36 | 显示全部楼层 |阅读模式

具体情况是这样的,我绑定了 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.     }
复制代码
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2017-12-11 13:30:17 | 显示全部楼层


你前面的设置就是都跳到 https://www.xxx.com
可以把前面的 return 301 https://www.xxx.com$request_uri; 改成 return 301 https://$server_name$request_uri; 重启nginx
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2017-12-12 08:43:36 | 显示全部楼层

回复 2# 的帖子


输入   xxx.com  可以转跳  但是  输入  https://xxx.com   就不能转跳到  https://www.xxx.com 了
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2017-12-12 14:32:56 | 显示全部楼层

回复 3# 的帖子




最简单的方法,把https的站点配置复制一份,去掉其中www的域名,加上前面说的设置301的语句,再把带www域名https站点里的不带www的域名删掉
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-24 23:22 , Processed in 0.030445 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表