Nginx 中更好的 VHOST 管理?
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用虚拟主机的通用设置创建一个文件(即 vhost.conf)。无论您想在何处使用此通用设置,只需包含该 vhost.conf 文件即可。
路径是相对于 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.
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