有效重写的状态404,预期的索引处理程序

问题描述 投票:1回答:1

location /有一个@rewriteIt但有些东西是worg ......

全新安装NGINX到UBUNTU 16 LTS,所有apt标准。

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

测试状态和动态页面,除了重写之外都很好:

使用脚本

example.com

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;
        }
}

改为try_files $uri $uri/ @rewriteIt;时也一样。

默认

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;
        }
}
nginx url-rewriting
1个回答
1
投票

命名位置需要是try_files语句的最后一个参数,替换=404术语。有关详细信息,请参阅this document

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

© www.soinside.com 2019 - 2024. All rights reserved.