Nginx 重写或内部重定向循环,同时内部重定向到“/index.html”

问题描述 投票:0回答:3

我用Php框架在nginx上实现Web服务器,没有任何index.html,网页工作正常,但有些脚本不起作用,它说“500内部服务器错误”

这是服务器日志

2016/11/16 11:08:38 [错误] 2551#0: *738 重写或内部重定向循环,同时内部重定向到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET /kelontong/getKelontong HTTP/1.1”,主机:“192.168.70.86”

2016/11/16 11:09:20 [错误] 2551#0: *746 重写或内部重定向循环,同时内部重定向到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET /kelontong/getKelontong HTTP/1.1”,主机:“192.168.70.86”

2016/11/16 11:14:47 [错误] 5500#0: *4 重写或内部重定向循环,同时内部重定向到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET /部门/ HTTP/1.1”,主机:“192.168.70.86”

2016/11/16 11:14:48 [错误] 5500#0: *6 重写或内部重定向循环,同时内部重定向到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET /department/getdepartment HTTP/1.1”,主机:“192.168.70.86”

2016/11/16 11:18:56 [错误] 5518#0: *4 重写或内部重定向循环,同时内部重定向到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET /department/getdepartment HTTP/1.1”,主机:“192.168.70.86”

2016/11/16 11:18:56 [错误] 5520#0: *8 重写或内部重定向循环,同时内部重定向到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET /department/getdepartment HTTP/1.1”,主机:“192.168.70.86”

2016/11/16 11:21:35 [错误] 5534#0: *3 重写或内部重定向循环,同时内部重定向到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET /department/getdepartment HTTP/1.1”,主机:“192.168.70.86”

这是我的 nginx 主机配置文件

server {
 listen 443 ssl http2;

 root /bwi/foreverstore.id;
 index index.html index.htm index.php;


 server_name www.foreverstore.id ;
 ssl_certificate /etc/nginx/ssl/foreverstore.crt;
 ssl_certificate_key /etc/nginx/ssl/foreverstore.key;

 location / {

    try_files $uri $uri/ /index.html;
    #  try_files $uri $uri/ =404;
    # 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;
    allow ::1;
    deny all;
 }

 error_page 404 /404.html;
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
    root /usr/share/nginx/www;
 }

 location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_param MAGE_RUN_CODE default;
    fastcgi_param MAGE_RUN_TYPE store;
  }
}

如果你们知道如何解决这个问题,我将非常感谢你们 干杯。

php nginx web
3个回答
6
投票

我认为 try_files 行应该如下所示:

try_files $uri $uri/ index.html;


0
投票

问题来自这一行:

try_files $uri $uri/ /index.html;

当您的服务器上不存在 $uri$uri//index.html 时,就会发生错误。


-1
投票

由于您没有像您所说的那样使用任何 html 文件,因此更改您的根位置块:

location / {
 try_files $uri $uri/ =404;
}

你还必须在你的 php 块中包含一个 try 文件,这样当它失败时,它就会去那里而不是寻求重定向:

location ~ \.php$ {
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
  fastcgi_intercept_errors on;
  fastcgi_param MAGE_RUN_CODE default;
  fastcgi_param MAGE_RUN_TYPE store;
  try_files $uri $uri/ =404;
}

既然您声明了:

error_page 404 /404.html;
您还可以添加404位置:

    location = /404.html {
            root /usr/share/nginx/html/;
            internal;
    }

这应该可以阻止那些丑陋的重定向循环。

© www.soinside.com 2019 - 2024. All rights reserved.