laplaceon
By:
laplaceon

Subdomain in nginx not working

May 22, 2014 2.7k views
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?
6 Answers
Going to have to see your config file - at least the important parts.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html/main;
index index.html index.htm index.php;

# Make site accessible from http://localhost/
server_name localhost;
include hhvm.conf;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
}

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

root /usr/share/nginx/html/api;
index index.html index.htm index.php;

# Make site accessible from http://localhost/
server_name api.airiverse.com;
include hhvm.conf;
}
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?
Yes I have added an A record named api with my IP address
Try the following config instead: https://p.kk7.me/susuyidoya.nginx.

Also, can you pastebin the contents of hhvm.conf?
Have another answer? Share your knowledge.