我使用Php框架在nginx上实现了web服务器,没有任何index.html,网页工作正常,但有些脚本不工作,它说“500内部服务器错误”
这是服务器日志
2016/11/16 11:08:38 [错误] 2551#0:* 738重写或内部redirect周期内部redirect到“/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 [error] 2551#0:* 746重写或内部redirect周期内部redirect到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET / kelontong / getKelontong HTTP / 1.1”,主机:“192.168.70.86”
- 无法启动ubuntu服务器中的Nginx服务器
- 将RoR部署到AWS Beanstalk时发生Nginx错误
- 当redirect到https时,Nginx不从根服务器
- Gunicorn和Django错误权限被拒绝
- 使用代理协议的kubernetes nginx入口最终以损坏的标题结束
2016/11/16 11:14:47 [error] 5500#0:* 4重写或内部redirect周期内部redirect到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET / department / HTTP / 1.1”,主机:“192.168.70.86”
2016/11/16 11:14:48 [error] 5500#0:* 6重写或内部redirect周期内部redirect到“/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 [error] 5518#0:* 4重写或内部redirect周期内部redirect到“/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重写或内部redirect周期内部redirect到“/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重写或内部redirect周期内部redirect到“/index.html”,客户端:27.131.251.6,服务器:www.foreverstore.id,请求:“GET / department / getdepartment HTTP / 1.1”,主机:“192.168.70.86”
这是我的nginx主机configuration文件
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; } }
如果你们知道如何解决这个问题,我会很感激你们的欢呼声。
我认为try_files行应该是这样的:
try_files $uri $uri/ index.html;
由于您没有使用任何html文件,所以请更改您的根位置块:
location / { try_files $uri $uri/ =404; }
你必须包括一个尝试文件,以及在您的PHP块,所以当它失败它去那里,而不是寻求重定向:
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; }
这应该阻止那些丑陋的重定向循环。