Can subdomains be used with an ip with Nginx for testing

July 26, 2014 4.5k views

Before I transfer a domain I would like to know I have the config files setup correctly.
I don't seem to be able to use
server_name sub1.192.241.223.202
in

server {
    listen 0.0.0.0:80;
    server_name sub1.192.241.223.202; 
    access_log /var/log/nginx/ddAppSub1.log;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;
    proxy_pass http://127.0.0.1:9000;
    }
}

Will changing the ip above to MyDomain work when the domain is transfered?

server_name sub1.MyDomain.com;
3 Answers

IP address cannot have subdomains. But, you can configure nginx to listen on server_name sub1.mydomain.com and add the following line to /etc/hosts locally so that sub1.mydomain.com points to your droplet's IP address:

1.2.3.4 sub1.mydomain.com

I transfered my domain. that's working.
Added an A record so my domain has two A records
@ and
sub1 both pointing to the ip of my droplet 192.241.223.202
added a new file to /etc/nginx/sites-enabled with

server {
    listen 0.0.0.0:80;
    server_name sub1.cornerpins.com;
    access_log /var/log/nginx/ddAppSub1.log;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;
    root /opt/cornerpinsRoot;
    index index.html index.htm;      
    }
}

sub1 is just pointing to the root menu for now....

reloaded nginx

navigating to http://sub1.cornerpins.com fails....

Yikes its working now!! ... so there must have been a few minutes delay between adding the A record...
Thanks for your help

Have another answer? Share your knowledge.