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

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

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


当前回答

如果在Ubuntu上使用apt-get安装,请尝试/usr/share/nginx/www.

编辑:

在最近的版本中,路径已更改为: /usr/share/nginx/html

2019编辑:

你也可以试试/var/www/html/index.nginx-debian.html。

其他回答

你可以访问nginx文件配置,你可以看到root /path。在这个 nginx apache的默认地址是/var/www/html

转储配置:

$ 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

查看nginx配置文件来确定。 这个命令是greps在你的机器上配置的任何东西:

cat /etc/nginx/sites-enabled/default |grep "root"

在我的机器上,它是:root /usr/share/nginx/www;

如果在Ubuntu上使用apt-get安装,请尝试/usr/share/nginx/www.

编辑:

在最近的版本中,路径已更改为: /usr/share/nginx/html

2019编辑:

你也可以试试/var/www/html/index.nginx-debian.html。

我在Digital Ocean用nginx运行WordPress网站时也遇到了这个问题。

我的解决方案如下:

修改/etc/nginx/nginx.conf文件如下:

server {
root /var/www/html;
}

然后我必须sudo服务nginx重启

nginx -V命令也显示你的nginx配置文件的位置(我的是指向/etc/nginx/nginx.conf)