我可以在 Nginx 上为每个目录添加不同的 conf 文件吗?
Can I add different conf file per directory on Nginx?
我想将不同的配置文件添加到不同的目录。例如:
root /var/www/root/html
location / {
root /var/www/root/html
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
include a.conf
include phphandler.conf
}
location /dir1/ {
root /var/www/dir1/html
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
include b.conf
}
location /dir2/ {
root /var/www/dir2/html
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
include c.conf
include phphandler.conf
}
所以每个目录都有自己的 .conf 文件(例如 a.conf、b.conf),其中包含自己的 php 处理选项、错误处理选项等,并且有一个通用的 conf 文件(phphandler.conf) 其中包含适用于所有子目录的配置。
这行得通吗?我想为每个子目录分离错误页面和配置文件。
此外,更新 nginx 是否会将 /site-available/default 恢复为默认配置?
你的问题的答案是肯定的,它会起作用,但不要在 location /
中这样做
在你的主 nginx.conf
中,你必须编写要包含的路径
比如现在你只有一个include /etc/nginx/sites-enabled/*;
再加一个include /etc/nginx/yourdir/*;
我想将不同的配置文件添加到不同的目录。例如:
root /var/www/root/html
location / {
root /var/www/root/html
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
include a.conf
include phphandler.conf
}
location /dir1/ {
root /var/www/dir1/html
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
include b.conf
}
location /dir2/ {
root /var/www/dir2/html
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
include c.conf
include phphandler.conf
}
所以每个目录都有自己的 .conf 文件(例如 a.conf、b.conf),其中包含自己的 php 处理选项、错误处理选项等,并且有一个通用的 conf 文件(phphandler.conf) 其中包含适用于所有子目录的配置。
这行得通吗?我想为每个子目录分离错误页面和配置文件。
此外,更新 nginx 是否会将 /site-available/default 恢复为默认配置?
你的问题的答案是肯定的,它会起作用,但不要在 location /
在你的主 nginx.conf
中,你必须编写要包含的路径
比如现在你只有一个include /etc/nginx/sites-enabled/*;
再加一个include /etc/nginx/yourdir/*;