How to Enable a Site with Nginx on Ubuntu
Published: 2024-07-11 | Updated: 2024-07-12Situation
You have Ubuntu all set up. Nginx is istalled. The default Nginx site displays in your browser. Now it’s time to configure Nginx to direct requests related to your domain to your domain’s app request handlers.
Steps to Enable Your Site
In Ubuntu’s Nginx installation there will be two direcories /etc/nginx/sites-enabled
and /etc/nginx/sites-available
.
1. Add Your Nginx Config File
Create and upload a your-domain.conf
file to the /etc/nginx/sites-available
directory.
2. Enable Your Nginx Config File
In this step we are creating a symbolic link from the available site’s configuration file to the directory containing the list of sites Nginx looks at for enabled sites. Unsurprisingly this directory is called sites-enabled
.
sudo ln -s /etc/nginx/sites-available/your-domain.conf /etc/nginx/sites-enabled/
# or if running as root
ln -s /etc/nginx/sites-available/your-domain.conf /etc/nginx/sites-enabled/
3. Check Your Nginx Config
Before reloading Nginx it’s a good policy to check the configuration changes you’ve just made to ensure all is well. Why? Because if you have an error in your config file and Nginx can’t load it all your sites will be down.
This simple command will save you oodles of stress. Use it.
sudo service nginx -t
# or if running as root
service nginx -t
If there’s a problem, Nginx will find it and report it to you so you can fix it. In the meantime your server will continue to run just as it had been. Nice.
4. Reload Nginx
OK, so the config check found no problems. Time to reload Nginx
sudo service nginx reload
# or if running as root
service nginx reload