【发布时间】:2019-04-12 05:45:23
【问题描述】:
我有一个这样的 url 结构:
并想将其重写为:
为此,我尝试了大约 1000 种组合,这些组合基本上都归结为这段代码:
location /overview/ {
rewrite ^/overview/(.+)$ /triggers/overview.php?technician=$1 last;
}
我正在使用 Ajenti、php-fpm 7 和 nginx。
有什么想法吗?
这里还有整个 .conf 文件的上下文:
server {
listen *:80;
listen *:443 ssl;
ssl_certificate /certificates/fullchain.pem;
ssl_certificate_key /certificates/privkey.pem;
server_name subdomain.domain.com;
access_log /var/log/nginx/technicians.access.log;
error_log /var/log/nginx/technicians.error.log;
root /srv/technicians;
index index.html index.htm index.php;
# ACME challenge for letsencrypt
location ^~ /.well-known/acme-challenge {
alias /var/www/letsencrypt.sh;
}
# rewrite overview
rewrite_log on;
location /overview/ {
rewrite ^/overview/(.+)$ /triggers/overview.php?technician=$1 last;
}
# rewrite urls of requirements
rewrite ^/requirements/(.*)$ /requirements/$1.html last;
location ~ [^/]\.php(/|$) {
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass unix:/var/run/ajenti-v-php7.0-fcgi-technicians-php7.0-fcgi-0.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
【问题讨论】:
-
对我来说看起来不错。您是否有任何访问或错误日志。此外,您可以更改日志记录级别以非常详细地显示重写过程。见this link
-
感谢输入,不幸的是,即使启用了重写日志,错误日志中也没有任何内容。我为上下文信息添加了整个文件。
-
我应该提到重写日志记录级别是“通知”,因此您需要将配置中的语句更改为
error_log /var/log/nginx/technicians.error.log notice;才能看到它们。 -
真的很好奇。硬重启nginx后它工作了。似乎是一些缓存问题。
标签: php nginx url-rewriting