Nginx 中更好的 VHOST 管理?

发布于 2024-09-14 06:13:43 字数 385 浏览 2 评论 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;
}

My nginx.conf file is getting larger and large with dozens of vhosts repeating the same lines over and over. I was wondering if there is anyway to declare the following globally without having to repeat them for each project:

# 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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几味少女 2024-09-21 06:13:43

使用虚拟主机的通用设置创建一个文件(即 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

Create a file with the common setup for your vhosts (ie. vhost.conf). Wherever you would like to utilize this common setup, just include that vhost.conf-file.

server {
    include vhost.conf

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

Paths are relative to your nginx.conf-file, use absolute paths if specifying vhost.conf outside your nginx.conf-path. http://wiki.nginx.org/NginxHttpMainModule#include

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文