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

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

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


当前回答

正如这里的大多数用户所说,它是在这个路径下:

/usr/share/nginx/html

这是默认路径,但您可以创建自己的路径。

你所需要的是在web服务器根树中创建一个,并赋予它一些权限“不是0777”,只对一个用户和该用户可见,但路径的末尾对每个人都可见,因为路径的末尾是你的文件和文件夹将被公众查看的。

例如,你可以这样做:

home_web/site1/public_html/www/

无论何时你在Nginx中创建一个虚拟主机,你都可以自定义自己的根路径,只需在服务器块中添加如下内容:

 server {
    listen  80;
        server_name  yoursite.com;

root /home_web/site1/public_html/www/;
}

其他回答

对于CentOS、Ubuntu和Fedora,默认目录为/usr/share/nginx/html

在Mac上使用brew安装nginx:

/ usr / local / etc / nginx / nginx上。

location / { 
    root   html;  # **means /usr/local/Cellar/nginx/1.8.0/html and it soft linked to /usr/local/var/www**
    index  index.html;
}  

对于Ubuntu和docker映像:

 /usr/share/nginx/html/

'default public web root'可以在nginx -V output中找到:

nginx -V
nginx version: nginx/1.10.1
built with OpenSSL 1.0.2h  3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/var/lib/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/nginx.pid --lock-path=/run/nginx/nginx.lock --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --user=nginx --group=nginx --with-ipv6 --with-file-aio --with-pcre-jit --with-http_dav_module --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_v2_module --with-http_auth_request_module --with-mail --with-mail_ssl_module

前缀值是问题的答案。对于上面的示例,根目录是/var/lib/nginx

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;
        }

根节点是默认位置。