全球主机交流论坛备用站

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

nginx 无限循环301

[复制链接]

89

主题

846

回帖

2545

积分

金牌会员

Rank: 6Rank: 6

积分
2545
发表于 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. include rewrite/none.conf;
  53. #error_page 404 /404.html;

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

  56. include enable-php.conf;

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

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

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

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

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



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

使用道具 举报

53

主题

474

回帖

1651

积分

金牌会员

Rank: 6Rank: 6

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

使用道具 举报

89

主题

846

回帖

2545

积分

金牌会员

Rank: 6Rank: 6

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

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

使用道具 举报

4

主题

407

回帖

1270

积分

金牌会员

Rank: 6Rank: 6

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

使用道具 举报

25

主题

4008

回帖

9629

积分

论坛元老

Rank: 8Rank: 8

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

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

使用道具 举报

53

主题

474

回帖

1651

积分

金牌会员

Rank: 6Rank: 6

积分
1651
发表于 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,你的签名掉了~~~
回复 支持 反对

使用道具 举报

22

主题

1352

回帖

4024

积分

论坛元老

Rank: 8Rank: 8

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

使用道具 举报

89

主题

846

回帖

2545

积分

金牌会员

Rank: 6Rank: 6

积分
2545
 楼主| 发表于 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,你的签名掉了~~~
回复 支持 反对

使用道具 举报

89

主题

846

回帖

2545

积分

金牌会员

Rank: 6Rank: 6

积分
2545
 楼主| 发表于 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. 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. }
复制代码

也是不行
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, 2025-7-2 09:19 , Processed in 0.062158 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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