0

我的nginx.conf文件越来越大,数十个虚拟主机一遍又一遍地重复相同的行。我想知道是否无论如何都可以在全球范围内声明以下内容,而不必为每个项目重复它们:

# Route all requests for non-existent files to index.php
if (!-e $request_filename) {
 rewrite ^(.*)$ /index.php/$1 last;
}

location ~ \.php($|/) {
 include fastcgi_params;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_pass 127.0.0.1:9000;
}
4

1 回答 1

3

为您的虚拟主机创建一个具有通用设置的文件(即 vhost.conf)。无论您想在何处使用此通用设置,只需包含该 vhost.conf 文件即可。

server {
    include vhost.conf

    location /test {
        # Custom setup for /test
    }
}

路径相对于您的 nginx.conf 文件,如果在 nginx.conf 路径之外指定 vhost.conf,请使用绝对路径。http://wiki.nginx.org/NginxHttpMainModule#include

于 2010-08-16T19:58:47.343 回答