Question

Can subdomains be used with an ip with Nginx for testing

  • Posted July 26, 2014

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;
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.

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

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…

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