urlteste.oficial.news/my1返回状态404,和teste.oficial.news/other状态400 …但文件和PHP都很好。
server { server_name teste.oficial.news; root /var/www/teste; index index.php index.html index.htm; location / { try_files $uri $uri/ @proxy; } location @proxy { rewrite (my[23])$ ETC.php?cmd=$1 last; rewrite other$ index.html break; proxy_pass http://127.0.0.1; } location ~ \.php$ { try_files $uri =404; include /etc/nginx/fastcgi.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } include snippets/ssl-oficial.news.conf; } #end server
什么是worng?
我尝试了一个类似于你所描述的nginxconfiguration文件的例子:
root /var/www/teste; rewrite other$ index.html break;
在执行curl localhost/this/or/other ,这是根据tail /var/log/nginx/error.log在/var/log/nginx/error.log产生的错误消息:
2017/07/24 08:21:32 [error] 45637#0: *1 open() "/var/www/testeindex.html" failed (2: No such file or directory), client: 127.0.0.1, server: , request: "GET /this/or/other HTTP/1.1", host: "localhost
除非您的系统中存在此类文件,否则类似的原因您也将收到类似的讯息。
相同的rewrite (my[23])$ ETC.php?cmd=$1片段。
解决scheme :正确地重写文件 – 如果rewrite的replacement部分不是以scheme或斜线启动的,则可能是错误的。 在rewrite指令中撒上一些/符号。