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

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

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


当前回答

我在Ubuntu上的nginx是“nginx version: nginx/1.9.12 (Ubuntu)” 根路径为/var/www/html/

Ubuntu信息是: 没有LSB模块可用。 分销商ID: Ubuntu 描述:Ubuntu 16.04 LTS 版本:16.04 代号:主客关系的

实际上,如果你只是在Ubuntu上安装了nginx,那么你可以去“/etc/nginx/sites-available”并检查默认文件,有一个类似于“root/ web/root/path/goes/here”的配置。这就是你要找的。

其他回答

你可以搜索它,不管他们把它移动到哪里(系统管理移动或更新版本的nginx)

找到/ -name nginx

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重新启动。

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

编辑:

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

2019编辑:

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

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

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

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

转储配置:

$ 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