还有另一个redirect周期,是的。
看了其他问题,但似乎无法得到它的工作。
server { listen 80; server_name localhost; charset utf-8; access_log /srv/http/localhost/log/access.log; error_log /srv/http/localhost/log/error.log; location / { root /srv/http/localhost/www; index index.html index.php; } # prevent access to hidden files location ~ /\. { access_log off; log_not_found off; deny all; } # do not log assets location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { access_log off; log_not_found off; expires 360d; } # pass the PHP scripts to PHP-FPM socket location ~* \.php$ { try_files $uri /index.php; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; include fastcgi_params; } }
这是我的主要主机的完整server{}块,结果是:
2012/07/29 00:34:52 [error] 14810#0:* 10重写或内部redirect周期内部redirect到“/index.php”,客户端:xx.xx.xx.xx,服务器:本地主机,请求:“GET /phpinfo.php HTTP / 1.1”,主机:“xx.xx”
访问<anything>.php – index.php,phpinfo.php,i.php等
这导致500 Internal Server Error ,当我尝试try_files,我不时结束了404 ,但主要是redirect周期。
这里有什么问题?
你把try_files放在错误的location 。 它不应该在您将请求上传到php-fpm的location / ,而是位于您的location / 。
你也有root在错误的地方。 它应该在server块内,而不在location /块内。
最后,你需要一个fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_filename; 在location ~* \.php$块的location ~* \.php$ 。