找回密码
 立即注册
CeraNetworksBGVM服务器主机交流IP归属甄别会员请立即修改密码
查看: 59|回复: 9

nginx 无限循环301

[复制链接]

104

主题

697

回帖

2572

积分

金牌会员

积分
2572
发表于 2024-4-15 13:14:13 | 显示全部楼层 |阅读模式
本帖最后由 txjcv 于 2024-4-15 13:26 编辑
[ol]
  • server
  •     {
  •         listen 80;
  •         listen [::]:80;
  •         server_name test.com ;
  •         index index.html index.htm index.php default.html default.htm default.php;
  •         root  /home/wwwroot/test.com;
  •         #include rewrite/none.conf;
  •         #error_page   404   /404.html;
  •         # Deny access to PHP files in specific directory
  •         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
  •         include enable-php.conf;
  •         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  •         {
  •             expires      30d;
  •         }
  •         location ~ .*\.(js|css)?$
  •         {
  •             expires      12h;
  •         }
  •         location ~ /.well-known {
  •             allow all;
  •         }
  •         location ~ /\.
  •         {
  •             deny all;
  •         }
  •         location / {
  •             return 301 https://$host$request_uri;
  •         }
  •         access_log  /home/wwwlogs/test.com.log;
  •     }
  • server
  •     {
  •         listen 443 ssl http2;
  •         listen [::]:443 ssl http2;
  •         server_name test.com ;
  •         index curl.html index.html index.htm index.php default.html default.htm default.php;
  •         root  /home/wwwroot/test.com;
  •         ssl_certificate /usr/local/nginx/conf/ssl/test.com/fullchain.cer;
  •         ssl_certificate_key /usr/local/nginx/conf/ssl/test.com/test.com.key;
  •         ssl_session_timeout 5m;
  •         ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  •         ssl_prefer_server_ciphers on;
  •         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";
  •         ssl_session_cache builtin:1000 shared:SSL:10m;
  •         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  •         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
  •         if ( $http_user_agent !~* curl ){  
  •          return 301 https://test.com/other/index.html;
  •         }  
  •         
  •         include rewrite/none.conf;
  •         #error_page   404   /404.html;
  •         # Deny access to PHP files in specific directory
  •         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
  •         include enable-php.conf;
  •         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  •         {
  •             expires      30d;
  •         }
  •         location ~ .*\.(js|css)?$
  •         {
  •             expires      12h;
  •         }
  •         location ~ /.well-known {
  •             allow all;
  •         }
  •         location ~ /\.
  •         {
  •             deny all;
  •         }
  •         access_log  /home/wwwlogs/test.com.log;
  •     }
  • [/ol]复制代码


    curl -I  --user-agent "Mozilla" http://test.com/other/index.html
    无限循环本身
  • 回复

    使用道具 举报

    73

    主题

    551

    回帖

    2413

    积分

    金牌会员

    积分
    2413
    发表于 2024-4-15 13:15:45 | 显示全部楼层
    带套了吧 把套的回源改成 443
    回复

    使用道具 举报

    104

    主题

    697

    回帖

    2572

    积分

    金牌会员

    积分
    2572
     楼主| 发表于 2024-4-15 13:17:37 | 显示全部楼层

    榆木 发表于 2024-4-15 13:15

    带套了吧 把套的回源改成 443

    没有套cdn
    我是这样的 curl 访问网站就让他默认访问一个 curl.html 无意的空白内容
    然后非curl访问的话我就让他301到 网站/other/index.html正常页面
    回复

    使用道具 举报

    7

    主题

    260

    回帖

    773

    积分

    高级会员

    积分
    773
    发表于 2024-4-15 13:15:00 | 显示全部楼层
    这种事情问GPT
    回复

    使用道具 举报

    42

    主题

    3148

    回帖

    7766

    积分

    论坛元老

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

    重复以上操作
    回复

    使用道具 举报

    73

    主题

    551

    回帖

    2413

    积分

    金牌会员

    积分
    2413
    发表于 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
    回复

    使用道具 举报

    86

    主题

    728

    回帖

    3085

    积分

    论坛元老

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

    使用道具 举报

    104

    主题

    697

    回帖

    2572

    积分

    金牌会员

    积分
    2572
     楼主| 发表于 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;


    也不行 ,非得要再开一个子域名网站吗?或者外部域
    回复

    使用道具 举报

    104

    主题

    697

    回帖

    2572

    积分

    金牌会员

    积分
    2572
     楼主| 发表于 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的配置


    我重新修改下[ol]
  • server
  •     {
  •         listen 80;
  •         listen [::]:80;
  •         server_name test.com ;
  •         index index.html index.htm index.php default.html default.htm default.php;
  •         root  /home/wwwroot/test.com;
  •         return 301 https://$server_name$request_uri;
  •         #include rewrite/none.conf;
  •         #error_page   404   /404.html;
  •         # Deny access to PHP files in specific directory
  •         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
  •         include enable-php.conf;
  •         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  •         {
  •             expires      30d;
  •         }
  •         location ~ .*\.(js|css)?$
  •         {
  •             expires      12h;
  •         }
  •         location ~ /.well-known {
  •             allow all;
  •         }
  •         location ~ /\.
  •         {
  •             deny all;
  •         }
  •         #location / {
  •         #    return 301 https://$host$request_uri;
  •         #}
  •         access_log  /home/wwwlogs/test.com.log;
  •     }
  • server
  •     {
  •         listen 443 ssl http2;
  •         listen [::]:443 ssl http2;
  •         server_name test.com ;
  •         index curl.html index.html index.htm index.php default.html default.htm default.php;
  •         root  /home/wwwroot/test.com;
  •         ssl_certificate /usr/local/nginx/conf/ssl/test.com/fullchain.cer;
  •         ssl_certificate_key /usr/local/nginx/conf/ssl/test.com/test.com.key;
  •         ssl_session_timeout 5m;
  •         ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  •         ssl_prefer_server_ciphers on;
  •         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";
  •         ssl_session_cache builtin:1000 shared:SSL:10m;
  •         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  •         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
  •         if ( $http_user_agent !~* curl ){  
  •          return 301 https://test.com/other/index.html;
  •         }  
  •         
  •         include rewrite/none.conf;
  •         #error_page   404   /404.html;
  •         # Deny access to PHP files in specific directory
  •         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
  •         include enable-php.conf;
  •         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  •         {
  •             expires      30d;
  •         }
  •         location ~ .*\.(js|css)?$
  •         {
  •             expires      12h;
  •         }
  •         location ~ /.well-known {
  •             allow all;
  •         }
  •         location ~ /\.
  •         {
  •             deny all;
  •         }
  •         access_log  /home/wwwlogs/test.com.log;
  •     }
  • [/ol]复制代码
    也是不行
  • 回复

    使用道具 举报

    86

    主题

    728

    回帖

    3085

    积分

    论坛元老

    积分
    3085
    发表于 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目录。
    回复

    使用道具 举报

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

    本版积分规则

    Archiver|手机版|小黑屋|HS2V主机综合交流论坛

    GMT+8, 2024-5-3 13:33 , Processed in 0.078564 second(s), 3 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2023 Discuz! Team.

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