Nginx 有效重写时的状态404,应为索引处理程序

Nginx 有效重写时的状态404,应为索引处理程序,nginx,url-rewriting,Nginx,Url Rewriting,location/有一个@rewriteIt,但有些东西在工作 将NGINX重新安装到ubuntu16lts中,全部aptstandard NGINX忽略了我的重写,为什么?如何修复example.com/foo重定向到test.php 测试状态和动态页面,除重写外,所有页面均正常: 嗯 错误(不适用于404) 嗯 嗯 嗯 用脚本 example.com 更改为try_files$uri$uri/@rewriteIt时相同 违约 命名位置必须是try\u files语句的最后一个参数,替换=

location/
有一个
@rewriteIt
,但有些东西在工作

将NGINX重新安装到ubuntu16lts中,全部
apt
standard

NGINX忽略了我的重写,为什么?如何修复
example.com/foo
重定向到
test.php

测试状态和动态页面,除重写外,所有页面均正常:

  • 错误(不适用于404)
用脚本

example.com 更改为
try_files$uri$uri/@rewriteIt时相同

违约
命名位置必须是
try\u files
语句的最后一个参数,替换
=404
术语。有关详细信息,请参阅


还有第二个错误。
nginx
中的所有URI都以一个前导的
/
开头,因此
rewrite
语句应该指定
/test.php?obj=$1
作为目标

您好,看到我的评论“更改为时相同”,但第二个错误似乎没有问题,我正在检查…谢谢Richard,现在正在运行!而且,是的,我们需要改变这两件事,不仅仅是第一件事,以便更好地工作。
server {
        server_name example.com www.example.com;

        root /var/www/example.com/;
        index  index.php index.html index.htm;

        location / {   # ignoring here?
                try_files $uri $uri/ @rewriteIt =404;
        }

        location  @rewriteIt {  # something wrong here?
                rewrite ^/?([a-zA-Z0-9\-]+)/?$    test.php?obj=$1            last;
        }

        location ~ \.php$ {
          include snippets/fastcgi-php.conf;
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
}
server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default_server ipv6only=on; ## listen for ipv6
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name localhost;
        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
           include snippets/fastcgi-php.conf;
           fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
}