1

I recently installed nginx on debian 8.8 server. I have registered a domain name and now I want to create a virtual host to serve it. (In the future I might add more virtual hosts for other domains.)

The problem is that every time I enter http://[my domain] I get the default nginx welcome page rather the one I created under /var/www/[my domain]/public_html.

Bellow I post the commands I typed to create a new vhost:

sudo mkdir -p /var/www/[my domain]/public_html
sudo chown -R www-data:www-data /var/www/[my domain]/public_html
sudo chmod -R 755 /var/www
sudo nano /var/www/[my domain]/public_html/index.html
sudo nano /etc/nginx/sites-available/[my domain]
sudo ln -s /etc/nginx/sites-available/[my domain] /etc/nginx/sites-enabled/[my domain]
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart

in the vhost file I added the bellow lines:

server {
    listen         80;
    listen         [::]:80;
    server_name    [my domain] www.[my domain];
}

server {
    listen         80;

    default_type text/plain;
    root   /var/www/[my domain]/public_html;
    index  index.html index.htm;

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

I checked the configurations with sudo nginx -t and no error reported.

I run ufw firewall with the following configurations (in case that someone wants them):

ssh                        ALLOW       Anywhere
Nginx HTTP                 ALLOW       Anywhere
shhh                       ALLOW       Anywhere (v6)
Nginx HTTP (v6)            ALLOW       Anywhere (v6)
2

The issue is that your virtual host where you specify your domain names has no other content.

You need to delete the first server block and move the server_name directive to the second block.

1
  • Oh really!!! I didn't knowing that. Thanks for your answer. May 30 '17 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.