我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。

我最近开始使用nginx,但我似乎找不到默认的公共web根。

我在哪里可以找到nginx的默认公共web根?


当前回答

如果您的配置不包括根/某些/绝对/路径;语句,或者它包含一个使用相对路径的语句,如root some/relative/path;,则结果路径取决于编译时选项。

如果您自己下载并编译源代码,那么可能只有一种情况可以让您对这对您意味着什么做出有根据的猜测。在这种情况下,路径将相对于使用的前缀。如果你没有更改它,它默认为/usr/local/nginx.你可以通过nginx -V找到nginx编译时使用的参数,它将——prefix作为第一个。

由于根指令默认为html,这当然会导致/usr/local/nginx/html作为你的问题的答案。

然而,如果你以任何其他方式安装nginx,所有的赌注都是失败的。您的发行版可能使用完全不同的默认路径。学习弄清楚您所选择的发行版使用哪种默认值完全是另一项任务。

其他回答

转储配置:

$ nginx -T
...
server {
    ...
    location / {
        root   /usr/share/nginx/html;
        ...
    }
    ...
}

你得到的可能是不同的,因为它取决于你的nginx是如何配置/安装的。

引用:

-T选项 -T选项

更新:关于是否/何时将-T选项添加到nginx的问题有一些混淆。vl-homutov于2015年6月16日在手册页中记录了它,这成为v1.9.2发行版的一部分。甚至在发行说明中也提到了。自那以后,t选项出现在每个nginx版本中,包括Ubuntu 16.04.1 LTS上可用的版本:

root@23cc8e58640e:/# nginx -h    
nginx version: nginx/1.10.0 (Ubuntu)
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/share/nginx/)
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file

Debian上Nginx的默认目录是/var/www/nginx-default。

可以查看“/etc/nginx/sites-enabled/default”文件

并找到

server {
        listen   80 default;
        server_name  localhost;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
                root   /var/www/nginx-default;
                index  index.html index.htm;
        }

根节点是默认位置。

Alpine Linux根本没有任何默认位置。文件/etc/nginx/conf.d/default.conf说:

# Everything is a 404
location / {
    return 404;
}

# You may need this to prevent return 404 recursion.
location = /404.html {
    internal;
}

替换成像root /var/www/localhost/htdocs这样的一行来指向你想要的目录。然后sudo service nginx restart重新启动。

导航到文件 $ cat /etc/nginx/nginx.conf

在HTTP——>服务器——>根下的文件中

在这里,您将看到根目录的默认位置和所有错误页面。

在Ubuntu中, Nginx默认根目录位置为/usr/share/nginx/html