FM-Wiki

Updates Nginx Config and Adding sites

by: Joshua James | Published: 2021-05-19

Making Changes to the Server Config on your Nginx hosts

your settings file is located here:

/etc/nginx/nignx.conf

If changes are made to your server config settings in NGinx, you can run the following command to check for errors.

sudo nginx -t

If there are no errors returned you will need to restart nginx to have your settings take hold. This can be dine by running the following command in shell:

systemctl restart nginx

Adding new vhosts in nginx

Adding new sites or virtual hosts in nginx can be done by adding new entrees in you /sites-available and /sites-enabled directories.
They are located at this path:

cd /etc/ngincd 

Example file structure

sites-available/
├── api
├── app
├── default
└── default.dpkg-dist
sites-enabled/
├── api -> /etc/nginx/sites-available/api
├── app -> /etc/nginx/sites-available/app
└── default -> /etc/nginx/sites-available/default

Your new site / vhost config files need to be added to /etc/nginx/sites-available. to make them active on your server, you can use a symbolic link to add the available site to your /etc/nginx/enabled-sites directory.

## replace <site-name> with the site you will be making active, example: app, or site.com
sudo ln -s /etc/nginx/sites-available/<site-name> /etc/nginx/sites-enabled/<site-name>

After your site has been successfully linked to your sites-active directory, we will need to test for errors and restart nginx to allow the server to see our changes.

 # change directory into folder that contains sites-active and sites-available
 cd /etc/nginx/

 # link desired site to make it active with a symbolic link (Example: vhosts is named app)
 sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/app

 # check for errors
 sudo nginx -t

 # restart the nginx service if no error was returned
 systemctl restart nginx
Back to All Notes