以下configuration:
location ~ /{ try_files /$uri /$uri/ /index.php?q=$uri&$args; }
当服务器返回500时,这将尝试几件事情。它将走下去,尝试下一件事情。 但是:因为这是一种失败的forms,表单被重新提交,直到错误的代码发生的事情发生了两次。 有没有办法只尝试一个try_files或替代try_files ?
使用=500在最后是不是一个解决scheme,因为它不会显示错误页面。
编辑我添加完整的服务器块。
我有一个复杂的设置与wordpress和laravel。 WordPress在主文件夹中,而所有对caup_api和子文件夹的调用都需要进行laravel安装。 因此,我有一个softlink caup_api -> ./caup_laravel/public/
这样我就可以使用所有的通话,通常使caup_api文件夹直接发送到laravel而不是由wordpress处理。 有问题的configuration是caup_api
server { listen 80; server_name dev.myapp.org; root /var/www/html/dev.myapp.org/public; index index.html index.htm index.php; access_log /var/log/nginx/nginx_lukas23.com.access.log; error_log /var/log/nginx/nginx_lukas23.com.error.log; location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } location = /apple-touch-icon.png { access_log off; log_not_found off; } location = /apple-touch-icon-precomposed.png { access_log off; log_not_found off; } location ~ /\.ht { deny all; access_log off; log_not_found off; } location / { try_files $uri $uri/ /index.php?q=$uri&$args; } location ~ \.php$ { proxy_intercept_errors on; error_page 500 501 502 503 = @fallback; fastcgi_buffers 8 256k; fastcgi_buffer_size 128k; fastcgi_intercept_errors on; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ##fastcgi_pass 127.0.0.1:9900; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; ##fastcgi_pass hhvm; } location @fallback { fastcgi_buffers 8 256k; fastcgi_buffer_size 128k; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ##fastcgi_pass 127.0.0.1:9900; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; ##fastcgi_pass jcrdev; } location ~* .(css|js|png|jpg|jpeg|gif|ico)$ { expires 1d; } location ~ /caup_api { try_files /caup_api/$uri /caup_api/$uri/ /caup_api/index.php?q=$uri&$args; } location ~ /causes { try_files /caup_api/$uri /caup_api/$uri/ /caup_api/index.php?q=$uri&$args; } }
你的代码运行两次,因为你明确要求它运行两次。
首先, try_filesfind你的URL,或者更具体地说它没有find你的URL,所以它运行你的PHP脚本,因为你用/index.php?...结束了它。 这会导致nginx使用location ~ \.php$的指令来执行脚本。
当这个返回一个500错误时,那个location的error_page 500 ...指令就会启动。这告诉nginx提供一个特定的文档,而不是它自己的内部500错误页面。 在你的情况下,它告诉nginx命中@fallback地点,这有再次调用你的PHP代码的效果。
要解决这个问题,你需要更仔细地考虑一下当你的程序发生500错误时你想要发生什么,或者更好的是不要返回500错误。