我有一组在我的应用程序中更改的 url 路径,例如:
- /dataview/unknownvvvo/ => /backend/unknown-vvvo
- /dataview/servicecounter => /backend/servicecounter-events
我尝试使用 nginx 中的重写规则来解决这个问题:
user app app;
error_log /dev/stderr debug;
events {}
http {
include mime.types;
default_type application/octet-stream;
rewrite_log on;
charset utf-8;
server {
listen 80;
listen [::]:80;
root /app/app/public;
index index.php index.html;
rewrite ^/dataview/unknownvvvo(.*)$ /backend/unknown-vvvo$1 last;
rewrite ^/dataview/servicecounter(.*)$ /backend/servicecounter-events$1 last;
location / {
try_files $uri /index.php$is_args$args;
}
location /index.php {
fastcgi_pass php-fpm_cms:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
但是,例如,当我在浏览器中调用“http://localhost/dataview/unknownvvvo”时,nginx 错误日志告诉我重写成功,但它给了我一个 404 错误: nginx_err
根据 nginx 文档,这应该可以工作,那么我在这里错过了什么?