Question

Can subdomains be used with an ip with Nginx for testing

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;

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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