【问题标题】:how is Nginx finding default rootNginx 如何找到默认根目录
【发布时间】:2021-07-12 10:28:51
【问题描述】:

我刚刚使用brew 安装了nginx,其默认配置位于/usr/local/etc/nginx。默认conf文件中的服务器配置如下(只粘贴了一小部分)

server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
...
}

提供index.html 的位置是/usr/local/var/www/。现在看上面的配置,不明白nginx是怎么去/usr/local/var/www/找默认文件的?是否有其他配置指示 nginx 查看该文件夹?

【问题讨论】:

    标签: nginx nginx-config


    【解决方案1】:
    1. 如果root 指令的值是相对的,则使用nginx 前缀组成完整路径。详情请见that answer
    2. In the nginx Homebrew formula --prefix 设置为 Homebrew 前缀:
          --prefix=#{prefix}
    
    1. 默认 Homebrew 前缀是 /usr/local on Intel
    2. 因此,根是html/usr/local/html(nginx 前缀+相对路径)。
    3. In the nginx Hombebrew formula这个位置符号链接到#{HOMEBREW_PREFIX}/var/www,也就是/usr/local/var/www
    # nginx's docroot is #{prefix}/html, this isn't useful, so we symlink it
    # to #{HOMEBREW_PREFIX}/var/www. The reason we symlink instead of patching
    # is so the user can redirect it easily to something else if they choose.
    

    【讨论】:

    • 这么好的解释。
    【解决方案2】:

    这样设置root html 使得 nginx 使用相对位置。 最简单的方法是用这样的完整路径编写根目录

    root /var/www/html;

    【讨论】:

      猜你喜欢
      • 2018-04-09
      • 2016-11-29
      • 1970-01-01
      • 2014-07-20
      • 2018-03-28
      • 2013-08-07
      • 2012-07-22
      • 2017-08-16
      • 2022-01-05
      相关资源
      最近更新 更多