【问题标题】:Can I add different conf file per directory on Nginx?我可以在 Nginx 上为每个目录添加不同的 conf 文件吗?
【发布时间】:2019-01-01 04:07:17
【问题描述】:

我想将不同的配置文件添加到不同的目录。例如:

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 文件(egaconf、b.conf),其中包含自己的 php 处理选项、错误处理选项等,并且有一个通用的 conf 文件(phphandler.conf),其中包含适用于所有子目录。

这行得通吗?我想为每个子目录分离错误页面和配置文件。

另外,更新 nginx 是否会将 /site-available/default 恢复为默认配置?

【问题讨论】:

  • 成功了吗?我建议您尝试一下并分享有关哪些问题的详细信息,以便人们帮助排除故障。

标签: php nginx configuration subdirectory


【解决方案1】:

您的问题的答案是肯定的,它会起作用,但不要在location / 中这样做

在您的主要nginx.conf 中,您必须编写要包含的路径

例如现在你只有一个include /etc/nginx/sites-enabled/*;

只需添加另一个include /etc/nginx/yourdir/*;

【讨论】:

  • 谢谢。我没有将它添加到 nginx.conf,而是在 /sites-available/default 中,我将把它符号链接到 /sites-enabled/
  • 另外,你的意思是我应该添加完整路径来“包含anything.conf”吗?以及“只需添加另一个包括/etc/nginx/yourdir/*;”是什么意思?什么意思?
  • @SmartPencil 是的,我的意思是添加完整路径
猜你喜欢
  • 2013-02-16
  • 1970-01-01
  • 2013-04-25
  • 1970-01-01
  • 1970-01-01
  • 2013-04-24
  • 1970-01-01
  • 2014-11-12
  • 1970-01-01
相关资源
最近更新 更多