drduinfu915094 2016-11-22 03:50
浏览 713

nginx&laravel:内部重定向到“/index.php”时重写或内部重定向循环

I am trying to upload my laravel app to my Digital Ocean droplet.

I followed this tutorial and now I am getting 500 server error.

here is my nginx error.log:

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"

I searched around for this error and I think there must be something wrong with my 'sites-available' files. I tried to play around with some values there but I couldn't get it to work yet.

here are the current contents of my '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;
    }

}

I think maybe the problem is in one of the try_files commands? I tried to comment-out the line pointed out in the code but I still have the same error. So it must be something else causing this.

  • 写回答

1条回答 默认 最新

  • dragon7713 2016-11-22 04:15
    关注

    Turns out the problem was that I had '\' before some '$' signs..

    I removed them and it worked like a charm.

    I will contact the tutorial author to correct his code.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?