The default public web directory for Nginx is specified in its configuration file, and it can vary based on the operating system and how Nginx was installed. Here's how you can find and understand the default public directory:
1. Default Location on Common Linux Distributions
Ubuntu/Debian:
- Default Directory:
/var/www/html Configuration File: The default configuration file is usually found at
/etc/nginx/sites-available/default.Example Configuration:
CentOS/RedHat:
- Default Directory:
/usr/share/nginx/html Configuration File: The default configuration file is usually found at
/etc/nginx/nginx.confor in/etc/nginx/conf.d/.Example Configuration:
2. How to Find the Default Directory
Check Nginx Configuration File:
Open the default server configuration file. For most distributions, you can check the default configuration files:
or
Check Active Configuration:
To ensure you're viewing the active configuration, you might want to list all the available server blocks:
3. Change the Default Directory
If you want to change the default document root to a different directory, you can modify the root directive in the Nginx configuration file.
Example Modification:
Open the Configuration File:
or
Change the
rootDirective:Update the
rootdirective to point to your desired directory. For example:
Test the Configuration:
This command checks the configuration for syntax errors.
Reload Nginx:
This applies the configuration changes without stopping the Nginx service.
Summary
- Default Public Directory:
- Ubuntu/Debian:
/var/www/html - CentOS/RedHat:
/usr/share/nginx/html
- Ubuntu/Debian:
- Find the Directory: Check the
rootdirective in the default Nginx configuration files, usually located in/etc/nginx/. - Change the Directory: Modify the
rootdirective in the Nginx configuration file and reload Nginx to apply changes.
By understanding and configuring the default public directory, you can effectively manage and serve your website’s static files using Nginx.