AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 505098
Accepted
pavs-maha
pavs-maha
Asked: 2013-05-05 21:06:39 +0800 CST2013-05-05 21:06:39 +0800 CST 2013-05-05 21:06:39 +0800 CST

这个 nginx 错误“rewrite or internal redirection cycle”是什么意思?

  • 772
tail -f /var/log/nginx/error.log
2013/05/04 23:43:35 [error] 733#0: *3662 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 127.0.0.1, server: _, request: "GET /robots.txt HTTP/1.1", host: "kowol.mysite.net"
HTTP/1.1", host: "www.joesfitness.net"
2013/05/05 00:49:14 [error] 733#0: *3783 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 127.0.0.1, server: _, request: "GET / http://www.qq.com/ HTTP/1.1", host: "www.qq.com"
2013/05/05 03:12:33 [error] 733#0: *4232 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", host: "joesfitness.net"

我从 nginx 错误日志中获取这些信息,我没有“kowol”子域,我的网站上没有任何指向 qq.com 或 joesfitness.net 的链接。这是怎么回事?

编辑:Nginx 默认配置:

server {
    listen   8080; ## listen for ipv4; this line is default and implied
    listen   [::]:8080 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.html;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    # Only for nginx-naxsi : process denied requests
    #location /RequestDenied {
        # For example, return an error code
        #return 418;
    #}

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    #error_page 500 502 503 504 /50x.html;
    #location = /50x.html {
    #   root /usr/share/nginx/www;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        #With php5-fpm:
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}
nginx
  • 7 7 个回答
  • 180682 Views

7 个回答

  • Voted
  1. Best Answer
    Michael Hampton
    2013-05-05T21:25:11+08:002013-05-05T21:25:11+08:00

    好吧,这是一个奇怪的问题,尽管我敢打赌问题在于:

            try_files $uri $uri/ /index.html;
    

    这里的问题是这里的第二个参数$uri/,导致index依次尝试指令中的每个文件。如果没有找到,它就会移动到,这会导致重新进入/index.html同一个块,并且由于它仍然不存在,您将陷入无限循环。location

    我会将其重写为:

            try_files $uri $uri/ =404;
    

    index如果您在指令中指定的索引文件都不存在,则返回 404 错误。


    顺便说一句,您看到的那些请求是Internet 背景噪音。特别是,它们是用于确定您的 Web 服务器是否是开放代理的探测器,并且可以被滥用以在恶意用户执行恶意活动时隐藏其来源。您的服务器在此配置中不是开放代理,因此您真的不需要担心。

    • 121
  2. markus
    2016-01-07T04:58:25+08:002016-01-07T04:58:25+08:00

    index.php如果您完全丢失,您也会收到此错误消息。

    • 17
  3. Wari Wahab
    2015-03-28T02:10:03+08:002015-03-28T02:10:03+08:00

    这很烦人。几周前它还在工作,今天我尝试时却失败了。

    nginx我相信 Ubuntu软件包的升级会导致 Ubuntu 保存标准索引文件的默认目录发生更改,因此该行:

    root /usr/share/nginx/www;
    

    将不再工作,因为文件的位置是/usr/share/nginx/html.

    要修复,只需将根指针更改为正确的目录,或创建指向新目录的符号链接:

    cd /usr/share/nginx
    sudo ln -s html www
    

    为我工作。

    • 10
  4. ulu
    2018-07-18T12:23:43+08:002018-07-18T12:23:43+08:00

    今天有这个错误,花几个小时找出原因。原来有人删除了该网站的所有文件。

    • 4
  5. Ninjaxor
    2014-11-27T14:46:44+08:002014-11-27T14:46:44+08:00

    我昨天遇到了这个问题,因为我正在通过缓存了不再存在的重定向的代理服务器测试 nginx。我的解决方案是$ sudo service squid3 restart在我连接的 squid3 代理服务器上。

    • 3
  6. Danila Vershinin
    2019-06-16T16:06:26+08:002019-06-16T16:06:26+08:00

    只是在发生这种情况时添加另一个案例。与接受的答案一样,通常,当尝试一系列位置然后创建某种内部重定向循环(永无止境)时,就会发生这种情况。

    它有时表现为错误的 NGINX 配置,甚至是限制性的 chmod(在某些锁定配置中)。这是例子。

    假设你有index.php前端控制器,像往常一样:

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~\.php {
       ...
    }
    

    您主要/some/thing通过您的index.php.

    但像往常一样,有一些 PHP 文件需要直接公开(因此location ~\.php不是location = /index.php.

    还假设您index.php被chmod-ded 到 0400 以进行安全锁定。

    在这种情况下一切仍然正常,只要该文件归“PHP-FPM 用户”所有。NGINX 不需要读取文件,因为它只是将文件名传递给 PHP-FPM 执行并取回 FastCGI 响应。

    然后你想处理当有人访问时会发生什么的情况,/non-existent.php因为使用这个相当标准的配置你会得到No input file specified.这种情况。

    为了解决这个问题,一些人补充说:

    if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
    

    好吧,根据 nginx 当然if是邪恶的,但这不是它。现在一切都会因重定向循环错误而中断。为什么?

    因为这个序列发生在一个循环中:

    • 请求URL时/some/page,nginx进入location /,没有找到真正的文件,转为/index.php
    • 然后它进入.php位置块并尝试检查它是否可以读取index.php。因为它不能,所以它将它重写为相同的index.php然后.php再次返回。
    • 1
  7. justnajm
    2021-12-08T07:30:17+08:002021-12-08T07:30:17+08:00

    您可以尝试从 default.conf“try_files”语法中删除 index.html:

    try_files $uri $uri/ /index.php?$query_string $uri/index.html;
    

    有了这个:

    try_files $uri $uri/ /index.php?$query_string;
    

    我意识到 nginx 正在尝试通过 index.php 解析 index.html 但在这一行上它返回到 index.html 并且它保持循环

    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve