VPS侦探论坛

标题: 请教军哥,https如何跳转到http [打印本页]

作者: robin    时间: 2018-6-19 17:52
标题: 请教军哥,https如何跳转到http
请教军哥,之前用的lnmp配置的免费SSL证书,但是最近不知道怎么都过期了,索性就改回http,但是搜索引擎记录的都还是https页面,有没有办法自动跳转到http呢?从论坛看到http 301到https的方法,反向操作没成功。
作者: licess    时间: 2018-6-20 08:54
把http到https 的301设置反过来就行了
https 主机上设置301,http 是正常的虚拟主机就行了
作者: robin    时间: 2018-6-20 20:15
标题: 回复 2# 的帖子
试了几次还是不行,请军哥看下下面的配置,
  1. server
  2.     {
  3.         listen 80;
  4.         #listen [::]:80;
  5.         server_name www.xxx.net xxx.net;
  6.         index index.html index.htm index.php default.html default.htm default.php;
  7.         root  /home/wwwroot/www.xxx.net;

  8.         include none.conf;
  9.         #error_page   404   /404.html;

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

  12.         include enable-php.conf;

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

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

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

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

  28.         access_log  /home/wwwlogs/www.xxx.net.log;
  29. return 301 http://www.xxx.net$request_uri;
  30.     }

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

  51.         include none.conf;
  52.         #error_page   404   /404.html;

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

  55.         include enable-php.conf;

  56.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  57.         {
  58.             expires      30d;
  59.         }

  60.         location ~ .*\.(js|css)?$
  61.         {
  62.             expires      12h;
  63.         }

  64.         location ~ /.well-known {
  65.             allow all;
  66.         }

  67.         location ~ /\.
  68.         {
  69.             deny all;
  70.         }

  71.         access_log  /home/wwwlogs/www.xxx.net.log;
  72.     }
复制代码

作者: licess    时间: 2018-6-21 08:36
标题: 回复 3# 的帖子
你这配置能成功才怪
http虚拟主机你加啥301,删掉
https虚拟主机里你加啥if,判断啥host,判断删掉只留301代码,另外server_name都没写全,none www的域名呢
作者: robin    时间: 2018-6-21 08:47
标题: 回复 4# 的帖子
感谢军哥百忙之中还能回复,修改后貌似还是不行,代码如下:
  1. server
  2.     {
  3.         listen 80;
  4.         #listen [::]:80;
  5.         server_name www.xxx.net xxx.net;
  6.         index index.html index.htm index.php default.html default.htm default.php;
  7.         root  /home/wwwroot/www.xxx.net;

  8.         include none.conf;
  9.         #error_page   404   /404.html;

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

  12.         include enable-php.conf;

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

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

  21.         location ~ /.well-known {
  22.             allow all;
  23.         location ~ /\.
  24.         {
  25.             deny all;
  26.         }

  27.         access_log  /home/wwwlogs/www.xxx.net.log;
  28.     }

  29. server
  30.     {
  31.         listen 443 ssl http2;
  32.         #listen [::]:443 ssl http2;
  33.         server_name www.xxx.net xxx.net;
  34.         index index.html index.htm index.php default.html default.htm default.php;
  35.         root  /home/wwwroot/www.xxx.net;
  36.         return 301 http://www.xxx.net$request_uri;
  37.         ssl on;
  38.         ssl_certificate /etc/letsencrypt/live/www.xxx.net/fullchain.pem;
  39.         ssl_certificate_key /etc/letsencrypt/live/www.xxx.net/privkey.pem;
  40.         ssl_session_timeout 5m;
  41.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  42.         ssl_prefer_server_ciphers on;
  43.         ssl_session_cache builtin:1000 shared:SSL:10m;
  44.         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  45.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

  46.         include none.conf;
  47.         #error_page   404   /404.html;

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

  50.         include enable-php.conf;

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

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

  59.         location ~ /.well-known {
  60.             allow all;
  61.         }

  62.         location ~ /\.
  63.         {
  64.             deny all;
  65.         }

  66.         access_log  /home/wwwlogs/www.xxx.net.log;
  67.     }
复制代码

作者: licess    时间: 2018-6-21 18:02
标题: 回复 5# 的帖子
可能没重启或reload nginx,没有的话配置文件肯定不会生效
作者: Ang    时间: 2018-6-21 21:04
做个猜想,会不会跟HSTS有关?比如之前设置过这个,时间又比较长,据说一旦进了这个目录,后头一直会以SSL加密方式走。

不过楼主为何不再继续申请和续SSL证书呢?一键包下,这个挺方便的,何况你引擎上收录的还已经是HTTPS了。
作者: licess    时间: 2018-6-22 10:26
标题: 回复 5# 的帖子
另外301也是有缓存的




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