Nginx Installed But Site Won't Load: Full Fix
In this article
If Nginx is installed but your site won't load, the cause is almost always a configuration error, a port conflict, or a firewall rule. This guide walks through the most common culprits and gives exact commands to diagnose and fix each one.
Why Nginx Installs but Doesn't Serve
Nginx is a web server that listens for incoming HTTP requests on port 80 (and HTTPS on 443). When you install it, the default configuration creates a basic site that should respond with a welcome page. If you see nothing, the server may not be running, the configuration may have a syntax error, the port may be blocked, or another service may already be using the port. Each of these has a distinct symptom and a straightforward fix.
Step 1: Is Nginx Actually Running?
First, confirm the process is alive. On most Linux distributions, use:
sudo systemctl status nginx– shows whether the service is active and any recent errors.- If it's not active, start it with
sudo systemctl start nginxand enable it to start on boot withsudo systemctl enable nginx. - If it fails to start, run
sudo systemctl status nginxagain to read the error message. The most common is a syntax error in a config file.
If you're on a system without systemd (like some containers), try sudo service nginx status or simply sudo nginx -t to test the configuration.
Step 2: Test the Configuration
A single typo in /etc/nginx/nginx.conf or a site file in /etc/nginx/sites-available/ can prevent Nginx from starting. Run:
sudo nginx -t
This tests the configuration and reports the line number of any error. Fix the error, then reload with sudo systemctl reload nginx (or sudo nginx -s reload). Common errors include missing semicolons, mismatched braces, or referencing a file that doesn't exist.
Step 3: Check the Port and Firewall
Even if Nginx is running, your firewall may block external access. On Ubuntu with UFW, allow HTTP and HTTPS:
sudo ufw allow 'Nginx Full'
Then check that Nginx is listening on port 80:
sudo netstat -tulpn | grep :80
If nothing shows, Nginx isn't bound to the port. If another service (like Apache) is using port 80, you'll see it in the output. You can either stop that service or change Nginx's listen directive to another port (e.g., 8080) and access your site via http://your-server-ip:8080.
Step 4: Verify DNS and Virtual Host
If you're using a domain name, ensure it points to your server's IP. You can test locally with curl http://localhost – if that returns the Nginx welcome page, the server works and the issue is DNS or network. Also check that your site's configuration file in sites-available has a server_name matching your domain and that it's symlinked to sites-enabled:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Then reload Nginx.
Step 5: Look at the Error Logs
When nothing else makes sense, read the logs. The error log is usually at /var/log/nginx/error.log. Tail it while you reload or try to access the site:
sudo tail -f /var/log/nginx/error.log
Common log messages include "connection refused" (Nginx not running), "permission denied" (file permissions on the web root), or "upstream sent too big header" (if using a reverse proxy).
Frequently Asked Questions
Why does my site show the default Nginx page instead of my content?
That means Nginx is running but your site's configuration isn't being used. Check that your server block's root points to the correct directory and that the index file exists. Also ensure your config file is in sites-enabled and that you've reloaded Nginx.
What if I get a 403 Forbidden error?
This usually means the web root directory doesn't have the right permissions. Nginx runs as the www-data user (on Debian/Ubuntu). Give that user read and execute permissions on the directory and read permission on files: sudo chown -R www-data:www-data /var/www/html or sudo chmod -R 755 /var/www/html.
How do I fix a "port 80 already in use" error?
Find the process with sudo lsof -i :80 or sudo netstat -tulpn | grep :80. Then either stop that service (e.g., sudo systemctl stop apache2) or change Nginx's listen directive to a different port. If you change the port, remember to include it in the URL (e.g., http://example.com:8080).
Why does my site load on localhost but not from another device?
This is almost always a firewall issue. Ensure your server's firewall allows incoming connections on port 80 (and 443). On cloud servers, also check the security group or network settings in your provider's dashboard.
Can I run Nginx and Apache at the same time?
Yes, but not on the same port. You can set Apache to listen on port 8080 and Nginx on port 80, or vice versa. You'll need to edit each server's config file to change the listen port and then restart both services.