How to add a new domain to your Nginx server

Saul Goodman May 15, 2019 Loading...

This article teaches you how to add a new site into your Nginx server in a few easy steps.

Step 1: create a directory structure within /var/www for your site ( by typing:

sudo mkdir -p /var/www/your-domain

Note that you can use another name for this folder instead of your-domain such as my-dog, my-cat, etc.

Step 2: assign ownership of the directory with the $USER environment variable:

sudo chown -R $USER:$USER /var/www/your-domain

Step 3: Set the permissions of your web roots by typing:

sudo chmod -R 755 /var/www/your-domain

Step 4: Create a sample index.html page to test your website.

nano /var/www/your-domain/index.html

And add some html code into it:

        <h1>This is a very professional website!</h1>

Save and close the html file.

Step 5: Create a file name in /etc/nginx/sites-available by typing:

sudo nano /etc/nginx/sites-available/

Then, coopy and paste the following code into this file:

server {
        listen 80;
        listen [::]:80;

        root /var/www/your-domain;
        index index.html index.htm index.php index.php7 index.php5 index.nginx-debian.html;


        location / {
                try_files $uri $uri/ =404;

Save and close the file.

Step 6: enable the file you’ve created in step 5 by creating a link from it to the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Step 7: restart your Nginx server:

sudo systemctl restart nginx

Step 8: Type “” or “” into your browser address bar to test your new site.


Related posts

Welcome to KINDACODE. Have a nice day and code well!