全球主机交流论坛备用站

 找回密码
 立即注册

QQ登录

只需一步,快速开始

全球云38元起免备案V2EX搬瓦工VPS
SEO查询超级PING网站测速
Virmach特价鸡乌云漏洞吾爱破解
查看: 171|回复: 9

nginx 无限循环301

[复制链接]

41

主题

713

帖子

1827

积分

金牌会员

Rank: 6Rank: 6

积分
1827
发表于 2024-4-15 13:14:13 | 显示全部楼层 |阅读模式
20230417
本帖最后由 txjcv 于 2024-4-15 13:26 编辑
  1. server
  2.     {
  3.         listen 80;
  4.         listen [::]:80;
  5.         server_name test.com ;
  6.         index index.html index.htm index.php default.html default.htm default.php;
  7.         root  /home/wwwroot/test.com;
  8.         #include rewrite/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.         location / {
  29.             return 301 https://$host$request_uri;
  30.         }

  31.         access_log  /home/wwwlogs/test.com.log;
  32.     }

  33. server
  34.     {
  35.         listen 443 ssl http2;
  36.         listen [::]:443 ssl http2;
  37.         server_name test.com ;

  38.         index curl.html index.html index.htm index.php default.html default.htm default.php;
  39.         root  /home/wwwroot/test.com;

  40.         ssl_certificate /usr/local/nginx/conf/ssl/test.com/fullchain.cer;
  41.         ssl_certificate_key /usr/local/nginx/conf/ssl/test.com/test.com.key;
  42.         ssl_session_timeout 5m;
  43.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  44.         ssl_prefer_server_ciphers on;
  45.         ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
  46.         ssl_session_cache builtin:1000 shared:SSL:10m;
  47.         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  48.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

  49.         if ( $http_user_agent !~* curl ){  

  50.          return 301 https://test.com/other/index.html;

  51.         }  
  52.         
  53.         include rewrite/none.conf;
  54.         #error_page   404   /404.html;

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

  57.         include enable-php.conf;

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

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

  66.         location ~ /.well-known {
  67.             allow all;
  68.         }

  69.         location ~ /\.
  70.         {
  71.             deny all;
  72.         }

  73.         access_log  /home/wwwlogs/test.com.log;
  74.     }
复制代码



curl -I  --user-agent "Mozilla" http://test.com/other/index.html
无限循环本身
MJJ,你的签名掉了~~~
回复

使用道具 举报

52

主题

501

帖子

1566

积分

金牌会员

Rank: 6Rank: 6

积分
1566
发表于 2024-4-15 13:15:45 | 显示全部楼层
带套了吧 把套的回源改成 443
MJJ,你的签名掉了~~~
回复 支持 反对

使用道具 举报

41

主题

713

帖子

1827

积分

金牌会员

Rank: 6Rank: 6

积分
1827
 楼主| 发表于 2024-4-15 13:17:37 | 显示全部楼层
榆木 发表于 2024-4-15 13:15
带套了吧 把套的回源改成 443

没有套cdn
我是这样的 curl 访问网站就让他默认访问一个 curl.html 无意的空白内容
然后非curl访问的话我就让他301到 网站/other/index.html正常页面
MJJ,你的签名掉了~~~
回复 支持 反对

使用道具 举报

4

主题

189

帖子

618

积分

高级会员

Rank: 4

积分
618
发表于 2024-4-15 13:15:00 | 显示全部楼层
这种事情问GPT
MJJ,你的签名掉了~~~
回复 支持 反对

使用道具 举报

25

主题

2885

帖子

6971

积分

论坛元老

Rank: 8Rank: 8

积分
6971
发表于 2024-4-15 13:17:41 | 显示全部楼层
请求访问80
80收到,你应该跳转443
请求访问443
443收到,回源80

重复以上操作
MJJ,你的签名掉了~~~
回复 支持 反对

使用道具 举报

52

主题

501

帖子

1566

积分

金牌会员

Rank: 6Rank: 6

积分
1566
发表于 2024-4-15 13:18:26 | 显示全部楼层
txjcv 发表于 2024-4-15 13:17
没有套cdn
我是这样的 curl 访问网站就让他默认访问一个 curl.html 无意的空白内容
然后非curl访问的话我 ...

if ( $http_user_agent !~* curl ){  

         return 301 http://test.com/other/index.html;

        }  


改成 https://test.com/other/index.html
MJJ,你的签名掉了~~~
回复 支持 反对

使用道具 举报

20

主题

1095

帖子

3126

积分

论坛元老

Rank: 8Rank: 8

积分
3126
发表于 2024-4-15 13:20:23 | 显示全部楼层
你301不写在 location下,那不等于所有非curl请求都进行一遍301啊,包括已经301跳转的请求。
MJJ,你的签名掉了~~~
回复 支持 反对

使用道具 举报

41

主题

713

帖子

1827

积分

金牌会员

Rank: 6Rank: 6

积分
1827
 楼主| 发表于 2024-4-15 13:17:00 | 显示全部楼层
本帖最后由 txjcv 于 2024-4-15 13:23 编辑
榆木 发表于 2024-4-15 13:20
if ( $http_user_agent !~* curl ){  

         return 301 http://test.com/other/index.html;


也不行 ,非得要再开一个子域名网站吗?或者外部域
MJJ,你的签名掉了~~~
回复 支持 反对

使用道具 举报

41

主题

713

帖子

1827

积分

金牌会员

Rank: 6Rank: 6

积分
1827
 楼主| 发表于 2024-4-15 13:21:00 | 显示全部楼层
本帖最后由 txjcv 于 2024-4-15 13:27 编辑
wuxudd 发表于 2024-4-15 13:21
你301不写在 location下,那不等于所有非curl请求都进行一遍301啊,包括已经301跳转的请求。 ...


这个301是默认lnmp脚本的  http重定向到https的配置


我重新修改下
  1. server
  2.     {
  3.         listen 80;
  4.         listen [::]:80;
  5.         server_name test.com ;
  6.         index index.html index.htm index.php default.html default.htm default.php;
  7.         root  /home/wwwroot/test.com;
  8.         return 301 https://$server_name$request_uri;
  9.         #include rewrite/none.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.         #location / {
  30.         #    return 301 https://$host$request_uri;
  31.         #}

  32.         access_log  /home/wwwlogs/test.com.log;
  33.     }

  34. server
  35.     {
  36.         listen 443 ssl http2;
  37.         listen [::]:443 ssl http2;
  38.         server_name test.com ;

  39.         index curl.html index.html index.htm index.php default.html default.htm default.php;
  40.         root  /home/wwwroot/test.com;

  41.         ssl_certificate /usr/local/nginx/conf/ssl/test.com/fullchain.cer;
  42.         ssl_certificate_key /usr/local/nginx/conf/ssl/test.com/test.com.key;
  43.         ssl_session_timeout 5m;
  44.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  45.         ssl_prefer_server_ciphers on;
  46.         ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
  47.         ssl_session_cache builtin:1000 shared:SSL:10m;
  48.         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  49.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

  50.         if ( $http_user_agent !~* curl ){  

  51.          return 301 https://test.com/other/index.html;

  52.         }  
  53.         
  54.         include rewrite/none.conf;
  55.         #error_page   404   /404.html;

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

  58.         include enable-php.conf;

  59.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  60.         {
  61.             expires      30d;
  62.         }

  63.         location ~ .*\.(js|css)?$
  64.         {
  65.             expires      12h;
  66.         }

  67.         location ~ /.well-known {
  68.             allow all;
  69.         }

  70.         location ~ /\.
  71.         {
  72.             deny all;
  73.         }

  74.         access_log  /home/wwwlogs/test.com.log;
  75.     }
复制代码

也是不行
MJJ,你的签名掉了~~~
回复 支持 反对

使用道具 举报

0

主题

1

帖子

4

积分

新手上路

Rank: 1

积分
4
发表于 2024-4-15 13:21:16 | 显示全部楼层
txjcv 发表于 2024-4-15 13:25
这个301是默认lnmp脚本的  http重定向到https的配置

        if ( $http_user_agent !~* curl ){  

         return 301 https://test.com/other/index.html;

        }  

这一行,你在location下写,排除other目录。
wuxudd 发表于 2024-4-15 13:28
if ( $http_user_agent !~* curl ){  

         return 301 https://test.com/other/index.html ...

不行那这样的话会301到 http://test.com/other/index.html;
然后 http://test.com/other/index.html; 又301到  https://test.com/other/index.html;
MJJ,你的签名掉了~~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

展开

QQ|Archiver|手机版|小黑屋|全球主机交流论坛备用站

GMT+8, 2024-4-30 15:34 , Processed in 0.045058 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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