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

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

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


当前回答

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

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

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

其他回答

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

你可以简单地将nginx的根文件夹映射到你的网站的位置:

nano /etc/nginx/sites-enabled/default

在默认文件中,在服务器标签中寻找根,并更改网站的默认文件夹,例如,我的网站是在/var/www

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www; <-- Here!
...

当我在评估nginx, apache2和lighttpd时,我把它们都映射到我的网站/var/www.我发现这是最有效的评估方法。

然后可以启动/停止您选择的服务器,并查看哪个执行得最好。

如。

service apache2 stop
service nginx start

顺便说一下,nginx实际上非常快!

'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

在Mac OS X上,使用brew安装nginx会使默认目录:

/usr/local/var/www

So:

root html

意味着

root /usr/local/var/www/html

没有html目录,所以必须手动创建。

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

根节点是默认位置。