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 に答える