Question

Subdomain in nginx not working

  • Posted 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?

Subscribe
Share

Submit an 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.

Try the following config instead: <a href=“https://p.kk7.me/susuyidoya.nginx”>https://p.kk7.me/susuyidoya.nginx</a>. <br> <br>Also, can you pastebin the contents of <code>hhvm.conf</code>?

But its still not working

Yes I have added an A record named api with my IP address

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?

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>

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