重写 nginx 2 个参数

重写 nginx 2 个参数
server {

listen 127.0.0.1:80;
server_name ap5 www.ap5;

root home/ap5/public_html;

index index.php index.html;

log_not_found off;
access_log logs/ap5-access.log;
error_log logs/error.log error;
charset utf-8;

location ~ /\. { deny all; }
location = /favicon.ico { }
location = /robots.txt { }

     location ~ \.php$ {


        if (!-e $document_root$document_uri){return 404;}
        fastcgi_pass ap5:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include fastcgi_params;

    }



location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.htm index.php;


      rewrite ^/users/([a-z0-9\-]+)?$ /users.php?action=$1 last;
      rewrite ^/users/([a-z0-9\-]+)/([a-z0-9\-]+)?$ /users.php?action=$1&role=$2" last; 

}

位置@extensionless-php {

rewrite ^(.*)$ $1.php last;

}

}

首先,我是 Nginx 新手,所以不确定我是否做对了。我已经在 nginx 中完成了以下重写,我删除了 php 扩展,然后解析了请求。第一个请求工作正常,我有一个参数,另一个带有 2 个参数的请求有问题,因为页面总是重定向到 404 页面,但我不知道为什么。有人能帮忙吗?谢谢你的帮助

Here are the 2 requests

  rewrite ^/users/([a-z0-9\-]+)?$ /users.php?action=$1 last;
  rewrite ^/users/([a-z0-9\-]+)/([a-z0-9\-]+)?$ /users.php?action=$1&role=$2" last; 

丹尼

相关内容