【问题标题】:nginx & laravel: rewrite or internal redirection cycle while internally redirecting to "/index.php"nginx & laravel:重写或内部重定向循环,同时内部重定向到“/index.php”
【发布时间】:2017-04-05 15:11:24
【问题描述】:

我正在尝试将我的 laravel 应用上传到我的 Digital Ocean droplet。

我关注了这个tutorial,现在我收到 500 服务器错误。

这是我的 nginx 错误日志:

2016/11/22 02:21:30 [error] 7733#7733: *1 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 198.7.58.98, server: antique.samiemad.me, request: "GET / HTTP/1.1", host: "antique.samiemad.me"
2016/11/22 02:25:05 [error] 7733#7733: *2 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 52.71.155.178, server: antique.samiemad.me, request: "GET /robots.txt HTTP/1.1", host: "antique.samiemad.me"
2016/11/22 02:25:05 [error] 7733#7733: *3 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 52.71.155.178, server: antique.samiemad.me, request: "GET /info.php HTTP/1.1", host: "antique.samiemad.me"
2016/11/22 02:30:53 [error] 7733#7733: *4 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 198.7.58.98, server: antique.samiemad.me, request: "GET / HTTP/1.1", host: "antique.samiemad.me"
2016/11/22 02:32:30 [error] 7733#7733: *5 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 52.71.155.178, server: antique.samiemad.me, request: "GET /info.php HTTP/1.1", host: "antique.samiemad.me"
2016/11/22 02:35:52 [error] 7733#7733: *13 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 188.227.78.184, server: antique.samiemad.me, request: "GET / HTTP/1.1", host: "antique.samiemad.me"
2016/11/22 02:35:52 [error] 7733#7733: *14 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 188.227.78.184, server: antique.samiemad.me, request: "GET /favicon.ico HTTP/1.1", host: "antique.samiemad.me", referrer: "http://antique.samiemad.me/"
2016/11/22 02:44:56 [error] 7733#7733: *15 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 198.7.58.98, server: antique.samiemad.me, request: "GET / HTTP/1.1", host: "antique.samiemad.me"
2016/11/22 02:57:59 [error] 7733#7733: *17 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 198.7.58.98, server: antique.samiemad.me, request: "GET / HTTP/1.1", host: "antique.samiemad.me"
2016/11/22 03:02:30 [error] 7733#7733: *18 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 198.7.58.98, server: antique.samiemad.me, request: "GET / HTTP/1.1", host: "antique.samiemad.me"

我四处寻找这个错误,我认为我的“站点可用”文件一定有问题。我尝试在那里使用一些值,但我还不能让它工作。

这是我的 'sites-available/antique.samiemad.me' 的当前内容:

server {
    listen 80 ;
    listen [::]:80 ;

    root /var/www/antique.samiemad.me/public;
    index index.php index.html index.htm;

    server_name antique.samiemad.me;
    charset   utf-8;

    gzip on;
    gzip_vary on;
    gzip_disable "msie6";
    gzip_comp_level 6;
    gzip_min_length 1100;
    gzip_buffers 16 8k;
    gzip_proxied any;
    gzip_types
        text/plain
        text/css
        text/js
        text/xml
        text/javascript
        application/javascript
        application/x-javascript
        application/json
        application/xml
        application/xml+rss;

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

    location ~ \.php\$ {
        try_files \$uri /index.php =404; # tried to comment-out this line.. no luck :(
        fastcgi_split_path_info ^(.+\.php)(/.+)\$;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)\$ {
      expires 1M;
      access_log off;
      add_header Cache-Control "public";
    }

    location ~* \.(?:css|js)\$ {
      expires 7d;
      access_log off;
      add_header Cache-Control "public";
    }

    location ~ /\.ht {
        deny  all;
    }

}

我认为问题可能出在 try_files 命令之一? 我试图注释掉代码中指出的行,但我仍然有同样的错误。所以这一定是其他原因造成的。

【问题讨论】:

    标签: php laravel redirect nginx digital-ocean


    【解决方案1】:

    原来问题是我在一些 '$' 符号之前有 '\'..

    我删除了它们,它就像一个魅力。

    我会联系教程作者更正他的代码。

    【讨论】:

    • 我遇到了类似的问题,虽然我的不一样(我有try_files $uri $uri/ /index.php?$args;,但我仍然遇到这个烦人的循环!)。另外,很高兴看到这篇文章的作者还没有修复它=)
    【解决方案2】:

    您可以尝试从 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 并保持循环

    【讨论】:

      猜你喜欢
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      • 2013-08-21
      • 1970-01-01
      相关资源
      最近更新 更多