Understanding Nginx Default Public Web Root

Nginx is a popular web server known for its high performance, scalability, and reliability. When setting up a website or application with Nginx, it’s essential to understand where the default public web root is located. The default public web root, also known as the document root, is the directory where Nginx serves files from by default.

By default, Nginx uses the root directive in its configuration file to specify the location of the document root. If no root directive is specified or it’s set to a relative path, the resulting path depends on the compile-time options used when building Nginx.

When installing Nginx using a package manager like apt-get on Ubuntu, the default public web root is usually /usr/share/nginx/www for older versions and /usr/share/nginx/html for newer versions. However, this can vary depending on the Linux distribution being used.

To find the default public web root on your system, you can check the Nginx configuration file, typically located at /etc/nginx/sites-enabled/default. Look for the root directive within the location / block, which specifies the document root. For example:

server {
    listen   80 default;
    server_name  localhost;

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

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

In this example, the default public web root is /var/www/html.

Alternatively, you can use the nginx -V command to display the compile-time options used when building Nginx. The --prefix option specifies the base directory for Nginx, and the default public web root is usually located within this directory. For example:

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

In this example, the --prefix option is set to /var/lib/nginx, which means the default public web root is likely located at /var/lib/nginx/html.

In summary, the default public web root for Nginx can vary depending on the installation method and Linux distribution. To find the default public web root, check the Nginx configuration file or use the nginx -V command to display the compile-time options.

Leave a Reply

Your email address will not be published. Required fields are marked *