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

时间:2018-11-08 16:50:36

标签: php nginx url-rewriting

我有这样的网址结构:

并希望将其重写为:

为此,我尝试了大约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;
    }

}

1 个答案:

答案 0 :(得分:0)

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

在Ajenti中,此方法无法通过用户界面使用,因此我通过php.ini进行了尝试,该方法可以正常工作。