Nginx用PHP重写规则无法正常工作



我有一个类似的url结构:

  • https://subdomain.domain.com/overview/test@hotmail.com

并希望将其重写为:

  • https://subdomain.domain.com/triggers/overview.php?technician=test@hotmail.com

为此,我尝试了大约1000种组合,这些组合基本上都归结为以下代码:

location /overview/ {
rewrite ^/overview/(.+)$ /triggers/overview.php?technician=$1 last;
}

我使用的是Ajanti,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;
}
}

我自己找到了解决方案:配置是正确的,我所要做的就是确保nginx真正重新启动。

在Ajanti中,这在UI中不起作用,所以我通过nginx -s reload进行了尝试,它起作用了。

最新更新