Question
Server Block not Working, it Goes to the Default Server Block
Hi,
I’m currently trying to add a Server Block for one of my domains but for some reason it’s not working, it goes to the default block when viewed on a browser, this is what I did.
Pointed my domain to the name server from Digitalocean.
NS1.DIGITALOCEAN.COM
NS2…Added the domain under the DNS menu in Digitalocean
mysitename.comCreated a folder for my site in the /var/www folder.
/var/www/mysitenameCreated an index.html file inside the mysitename folder.
/var/www/mysitename/index.htmlCreated the server block file.
/etc/nginx/sites-available/mysitename.com
*mysitename.com block content: *
server {
listen 80;
listen [::]:80;
root /var/www/mysitename;
index index.html index.htm;
server_name mysitename.com www.mysitename.com;
location / {
try_files $uri $uri/ =404;
}
- Enabled the server block. sudo ln -s /etc/nginx/sites-available/mysitename.com /etc/nginx/sites-enabled/
As you can see this is not set to be the default block but when I type mysitename.com it show the content from the block I have set as the default block.
Any idea what am I missing?
Thanks
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
After enabling the server block did you restart your nginx server so it picked up the new configuration?
No I did not, that’s actually what I was missing, problem solved. Thanks.
Quick question: I just noticed that if I type mysitename.com it works but if I add *www. *it doesn’t, any idea why?
Thanks a lot.
Make sure you add a CNAME record to your DNS pointing WWW back to your droplet. I saw this helpful post if you need tips on changing your DNS on Digital Ocean.
https://www.digitalocean.com/community/questions/using-cname-for-www-redirection