When setting up Nginx on Ubuntu 15.04, you'll encounter two potential default web root directories:
/usr/share/nginx/html /var/www/html
The /usr/share/nginx/html location comes from the Nginx package maintainers' default configuration. This follows traditional Unix filesystem hierarchy standards where:
/usr/sharecontains architecture-independent data- Package-maintained files typically reside here
Meanwhile, /var/www/html represents the more conventional Apache-style web root that many sysadmins expect. Ubuntu's LAMP stack defaults to this location.
The key difference in functionality comes down to permissions:
$ ls -ld /usr/share/nginx/html drwxr-xr-x 2 root root 4096 Jun 15 10:23 /usr/share/nginx/html $ ls -ld /var/www/html drwxr-xr-x 2 www-data www-data 4096 Jun 15 10:25 /var/www/html
The www-data user ownership of /var/www/html makes it more web-server friendly out of the box.
To use /usr/share/nginx/html effectively, you might need to adjust permissions:
sudo chown -R www-data:www-data /usr/share/nginx/html sudo chmod -R 755 /usr/share/nginx/html
Or update your Nginx config explicitly:
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Consider these factors when choosing:
- Package updates: Files in
/usr/share/nginx/htmlmight get overwritten during upgrades - Security:
/var/www/htmlis typically better isolated - Compatibility: Many deployment scripts expect
/var/www
If files aren't serving from either location, check:
# Verify Nginx is running systemctl status nginx # Check configuration syntax nginx -t # Examine error logs tail -f /var/log/nginx/error.log
Remember to restart Nginx after configuration changes:
sudo systemctl restart nginx
When working with Nginx on Ubuntu systems, you'll encounter two common default directories for serving web content:
/usr/share/nginx/html /var/www/html
Both directories may exist simultaneously, but they serve different purposes in the Linux filesystem hierarchy.
The /usr/share/nginx/html location is the traditional Nginx default, following Linux Filesystem Hierarchy Standard (FHS) guidelines where:
/usr/sharecontains architecture-independent data files- Nginx packages typically install sample files here
Meanwhile, /var/www/html has become a common alternative because:
/var/wwwis the conventional location for web content- Many administrators prefer keeping website files under
/var
Your ability to access files depends on Nginx configuration. Check your active config with:
grep root /etc/nginx/sites-enabled/*
Example server block showing both possibilities:
server {
listen 80;
server_name example.com;
# Option 1: Traditional Nginx default
# root /usr/share/nginx/html;
# Option 2: Common Apache-style location
root /var/www/html;
index index.html;
}
If you can't access files in /usr/share/nginx/html, check:
ls -la /usr/share/nginx/html
Ensure Nginx worker process has read access:
sudo chown -R www-data:www-data /usr/share/nginx/html sudo chmod -R 755 /usr/share/nginx/html
For production systems, we recommend:
- Using
/var/www/yourdomain.com/htmlstructure - Creating specific Nginx server blocks for each site
- Maintaining proper SELinux contexts if enabled
Example deployment script:
#!/bin/bash
DOMAIN="example.com"
WEB_ROOT="/var/www/${DOMAIN}/html"
sudo mkdir -p ${WEB_ROOT}
sudo chown -R $USER:$USER ${WEB_ROOT}
sudo chmod -R 755 /var/www