全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1025|回复: 17
打印 上一主题 下一主题

[翻译] nginx 跳转 https问题 (感谢各位回答!)

[复制链接]
跳转到指定楼层
1#
发表于 2021-1-19 13:44:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 3721 于 2021-1-19 14:16 编辑

感谢回答!已解决   方案如下:

  1.                 #访问http 跳转http
  2.                 server{
  3.                     listen 80;
  4.                     server_name 9i3.cn;
  5.                     rewrite ^/(.*)$ https://9i3.cn:443/$1 permanent;
  6.                 }
  7.                 #www跳转不带www
  8.                         server {
  9.                             listen       80;
  10.                             server_name  www.9i3.cn;
  11.                             return       301 https://9i3.cn$request_uri;
  12.                         }
复制代码




今天发现百度收录文章  收录了我 不带https 的  我奇怪了 我设置https 还认证https

但是怎么还是 收录http  查看一番  竟然不跳转  


访问  :  http://9i3.cn/interesting/327.html

竟然  不跳转  为 https://9i3.cn/interesting/327.html


试了其他文章 奇怪了   一样      最近换面板安装的 出现这个问题 。。 问下该怎么修改


访问  :  http://9i3.cn/interesting/327.html

跳转为  : https://9i3.cn/interesting/327.html



以下为nginx配置

  1. server {
  2.     listen 80;
  3.         listen 443 ssl;

  4.     root /wwwroot/typecho;
  5.     server_name 9i3.cn www.9i3.cn;

  6.     #日志文件路径,请不要随意更改,否则将导致面板无法获取到网站日志
  7.     error_log "/var/hwsmaster/wwwlogs/9i3.cn_FaCq-error.log";
  8.     access_log "/var/hwsmaster/wwwlogs/9i3.cn_FaCq-access.log";
  9.     limit_rate 0k;

  10.     #伪静态规则,如果删除,则面板设置的伪静态将失效
  11.     include /wwwroot/typecho/.htaccess;

  12.     #黑名单模式(允许所有,拒绝以下)
  13.     deny 54.255.93.11;
  14.     deny 18.163.128.157;
  15.     deny 113.0.161.50;
  16.     deny 13.114.87.202;
  17.     deny 45.10.1.85;
  18.     deny 107.173.149.117;
  19.     allow all;

  20.     #DENY FILES
  21.     location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
  22.     {
  23.         return 404;
  24.     }

  25.     #STATIC
  26.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  27.     {
  28.         expires 30d;
  29.         error_log off;
  30.         access_log /dev/null;
  31.     }
  32.     location ~ .*\.(js|css)?$
  33.     {
  34.         expires 12h;
  35.         error_log off;
  36.         access_log /dev/null;
  37.     }


  38.     #301重定向
  39.     if ($host ~ '^www.9i3.cn'){
  40.         return 301 https://9i3.cn$request_uri;
  41.     }

  42.     #SSL
  43.     ssl_certificate /var/hwsmaster/ssl/9i3.cn_wOsEx3QY.pem;
  44.     ssl_certificate_key /var/hwsmaster/ssl/9i3.cn_wOsEx3QY.key;
  45.     ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
  46.     ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
  47.     ssl_prefer_server_ciphers on;
  48.     ssl_session_cache shared:SSL:10m;
  49.     ssl_session_timeout 10m;

  50.     #PHP
  51.     location ~ [^/]\.php(/|$)
  52.     {
  53.         try_files $uri =404;
  54.         fastcgi_pass unix:/tmp/php-7.3.14-default.sock;
  55.         fastcgi_index index.php;
  56.         include fastcgi.conf;

  57.         set $real_script_name $fastcgi_script_name;
  58.         if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
  59.             set $real_script_name $1;
  60.             set $path_info $2;
  61.         }
  62.         fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
  63.         fastcgi_param SCRIPT_NAME $real_script_name;
  64.         fastcgi_param PATH_INFO $path_info;
  65.     }

  66.     error_page 404 /404.html;
  67.     index index.php default.php index.html index.htm default.html default.htm start.html;

  68. }
复制代码


2#
发表于 2021-1-19 13:56:29 | 只看该作者
  1. if ($server_port !~ 443){
  2.     rewrite ^(/.*)$ https://$host$1 permanent;
  3. }
复制代码

点评

还是一样的 我添加了  发表于 2021-1-19 14:01
3#
发表于 2021-1-19 13:57:08 | 只看该作者
  1. if ($host ~ '^www.9i3.cn'){
复制代码

访问  :  http://9i3.cn/interesting/327.html

竟然  不跳转  为 https://9i3.cn/interesting/327.html


你这个元老怎么水出来的

点评

术业有专攻  发表于 2021-1-19 14:02
4#
发表于 2021-1-19 14:01:13 来自手机 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
5#
发表于 2021-1-19 14:01:43 | 只看该作者

  1. server {
  2.     listen      80;
  3.     server_name .example.com;

  4.     location / {
  5.         return 301 https://example.com$request_uri;
  6.     }
  7. }
复制代码


http要单独配

https 配置到另一个 server 段

点评

感谢思路 解决了 不能写一起 。。  发表于 2021-1-19 14:14
6#
发表于 2021-1-19 14:02:31 | 只看该作者

  1. if ($scheme = http) {
  2.     return 301 https://$server_name$request_uri;
  3. }
复制代码

点评

感谢回答!  发表于 2021-1-19 14:22
感谢回答!  发表于 2021-1-19 14:18
7#
发表于 2021-1-19 14:07:29 | 只看该作者
安装一个宝塔   设置一下看他们怎么写的  
8#
发表于 2021-1-19 14:12:25 | 只看该作者
风怒了,编辑掉

点评

感谢回答!  发表于 2021-1-19 14:20
9#
发表于 2021-1-19 14:13:10 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
10#
发表于 2021-1-19 14:47:54 | 只看该作者
你的北岸为啥从2开始的

点评

主北岸 是org 域名 不然北岸了 然后被取消了 后面北岸就流从 2 3 4 5 这样的 4 5 被我注销北岸了 后面在北岸 7 8了  发表于 2021-1-19 14:57
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-10-19 01:26 , Processed in 0.074850 second(s), 20 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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