我有一个位置块/ ,通过任何虚拟pathindex.php指示在nginx陷阱页面。 我一直在使用这个设置一段时间,但最近我已经注意到,一些URL -在path段返回404在Nginx中,这意味着他们永远不会到达PHP脚本。 我不知道,如果它相关的-在url或不。 有些路线和它一起工作,有些则不。
作品: /profiles/recently-added
返回404: /explore/puerto-rico /puerto-rico
服务器块:
server { listen 80; server_name example.com; root /usr/share/nginx/hosts/www/; location ~ \.(php)$ { # commented out next 3 lines to see if that was the problem, but alas it made no change # try_files $uri = 404; # location ~ \..*/.*\.php$ {return 404;} # fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_keep_conn on; fastcgi_pass unix:/var/run/hhvm/hhvm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* .(png|gif|jpg|jpeg|ico|css|js)$ { include /etc/nginx/mime.types; expires 365d; } location / { include /etc/nginx/mime.types; index index.php; try_files $request_uri $request_uri/ /index.php?$query_string; } }
我正在努力了解我在这里做错了什么。 我以前曾经问过这个问题,而且没有得到好评。 nginx版本来自mainline分支,版本1.8.0
问题是这个位置正则expression式:
location ~* .(png|gif|jpg|jpeg|ico|css|js)$ { ^
这里的时期并不意味着只有一个时期 – 这意味着任何性格 。 因此它匹配rico的puerto-rico 。 要匹配一个实际的时期,它需要逃脱:
location ~* \.(png|gif|jpg|jpeg|ico|css|js)$ {
使用debugging日志将消除这些问题的奥秘。 从问题应用到configuration(为简洁起见,省略了一些行):
... 2016/06/08 12:38:58 [debug] 7056#7056: *133 http process request line 2016/06/08 12:38:58 [debug] 7056#7056: *133 http request line: "GET /puerto-rico HTTP/1.1" 2016/06/08 12:38:58 [debug] 7056#7056: *133 http uri: "/puerto-rico" 2016/06/08 12:38:58 [debug] 7056#7056: *133 http args: "" 2016/06/08 12:38:58 [debug] 7056#7056: *133 http exten: "" 2016/06/08 12:38:58 [debug] 7056#7056: *133 posix_memalign: 000000000229E060:4096 @16 2016/06/08 12:38:58 [debug] 7056#7056: *133 http process request header line 2016/06/08 12:38:58 [debug] 7056#7056: *133 http header: "User-Agent: curl/7.26.0" 2016/06/08 12:38:58 [debug] 7056#7056: *133 http header: "Accept: */*" 2016/06/08 12:38:58 [debug] 7056#7056: *133 http header: "Host: example.com" 2016/06/08 12:38:58 [debug] 7056#7056: *133 http header done 2016/06/08 12:38:58 [debug] 7056#7056: *133 event timer del: 7: 1465389598899 2016/06/08 12:38:58 [debug] 7056#7056: *133 generic phase: 0 2016/06/08 12:38:58 [debug] 7056#7056: *133 rewrite phase: 1 2016/06/08 12:38:58 [debug] 7056#7056: *133 test location: "/" 2016/06/08 12:38:58 [debug] 7056#7056: *133 test location: ~ "\.(php)$" 2016/06/08 12:38:58 [debug] 7056#7056: *133 test location: ~ ".(png|gif|jpg|jpeg|ico|css|js)$" 2016/06/08 12:38:58 [debug] 7056#7056: *133 using configuration ".(png|gif|jpg|jpeg|ico|css|js)$" ... 2016/06/08 12:38:58 [debug] 7056#7056: *133 http filename: "/var/www/puerto-rico" 2016/06/08 12:38:58 [debug] 7056#7056: *133 add cleanup: 0000000002301A48 2016/06/08 12:38:58 [error] 7056#7056: *133 open() "/var/www/puerto-rico" failed (2: No such file or directory), client: 127.0.0.1, server: example.com, request: "GET /puerto-rico HTTP/1.1", host: "example.com" 2016/06/08 12:38:58 [debug] 7056#7056: *133 http finalize request: 404, "/puerto-rico?" a:1, c:1 2016/06/08 12:38:58 [debug] 7056#7056: *133 http special response: 404, "/puerto-rico?" 2016/06/08 12:38:58 [debug] 7056#7056: *133 http set discard body 2016/06/08 12:38:58 [debug] 7056#7056: *133 xslt filter header 2016/06/08 12:38:58 [debug] 7056#7056: *133 HTTP/1.1 404 Not Found Server: nginx/1.8.0 Date: Wed, 08 Jun 2016 12:38:58 GMT Content-Type: text/html Content-Length: 168 Connection: keep-alive
显示nginx正在处理的请求。 这一行:
使用configuration“。(png | gif | jpg | jpeg | ico | css | js)$”
是确凿的证据表明请求符合你不期望的位置块,并且会把重点放在请求范围内的一个规则上。
显然,问题不是nginx相关的。 在hhvm上查找问题,尤其是在index.php存在的情况下,他们应该在URI的path上工作
index index.php;
也许,你想要重写URL。 请注意, .htaccess将无法正常工作 – 这是一个Apache的function。 对于nginx: http : //nginx.org/en/docs/http/ngx_http_rewrite_module.html