Report this

What is the reason for this report?

Subdomain in nginx not working

Posted on May 22, 2014

Hello, I followed a guide to making subdomains in nginx and created a new server block with the server name pointing to my subdomain (api.test.com) However when I go to the address, it shows the contents of test.com. Any ideas on what the problem is?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Going to have to see your config file - at least the important parts.

server { <br> listen 80 default_server; <br> listen [::]:80 default_server ipv6only=on; <br> <br> root /usr/share/nginx/html/main; <br> index index.html index.htm index.php; <br> <br> # Make site accessible from http://localhost/ <br> server_name localhost; <br> include hhvm.conf; <br> <br> location / { <br> # First attempt to serve request as file, then <br> # as directory, then fall back to displaying a 404. <br> try_files $uri $uri/ /index.html; <br> # Uncomment to enable naxsi on this location <br> # include /etc/nginx/naxsi.rules <br> } <br> <br> location /doc/ { <br> alias /usr/share/doc/; <br> autoindex on; <br> allow 127.0.0.1; <br> allow ::1; <br> deny all; <br> } <br>} <br> <br>server { <br> listen 80; <br> listen [::]:80; <br> <br> root /usr/share/nginx/html/api; <br> index index.html index.htm index.php; <br> <br> # Make site accessible from http://localhost/ <br> server_name api.airiverse.com; <br> include hhvm.conf; <br>} <br>

Your configuration looks fine. But maybe you get error because of listen [::]:80 default_server ipv6only=on; and listen [::]:80; are enabled which are for ipv6. DO currently don’t support ipv6. Try to comment those 2 and restart nginx. Also have you added the subdomain in your DNS?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.