To specify the document root for a website in Nginx, you need to modify the server block in the nginx.conf file or the configuration file of your website.
/etc/nginx/nginx.conf
or /usr/local/nginx/conf/nginx.conf
.http
block, locate the server
block that corresponds to your website's domain name or IP address. It will typically look like this:server {
listen 80;
server_name example.com;
...
}
server
block, add the root
directive to specify the document root directory:server {
listen 80;
server_name example.com;
root /path/to/document/root;
...
}
Replace /path/to/document/root
with the actual path to your website's document root directory. For example, if your website's files are located in /var/www/example.com/
, you would specify root /var/www/example.com/
.
sudo service nginx restart
, sudo systemctl restart nginx
, or sudo nginx -s reload
.After specifying the document root, Nginx will serve the files located in that directory when requests are made to your website.