Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Mon May 18, 2015 6:52 am 
Offline
Senior Newbie

Joined: Sat May 16, 2015 1:52 pm
Posts: 6
I'd like to add a couple of subdomains to my install.

I'm looking for one to be dev.example.com.

If I add dev.example.com under A records under DNS Manager, and add my server's IP address, people visiting example.com are directed to dev.example.com which is NOT what I want.

I would like dev.example.com to be a separate entity that resolves to the server's IP address but serves another folder. I've heard that this is done with CName's but I'm not too clear on that.
Would I just put in
Hostname: dev.example.com
Aliases to: dev.example.com
??


Top
   
PostPosted: Mon May 18, 2015 6:58 am 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
From a DNS standpoint, the end result is the same: dev.example.com returns your server's IP address. Doesn't matter how it's defined in the DNS. The response is entirely a function of your web server's configuration.

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
PostPosted: Mon May 18, 2015 9:00 am 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
If I add dev.example.com under A records under DNS Manager, and add my server's IP address, people visiting example.com are directed to dev.example.com which is NOT what I want.

That's not how it works. (Re)directing users to one site or another is the job of your server software, not DNS. Nobody is getting (re)directed anywhere unless you explicitly configure your server to do so. CNAME has nothing to do with it. What you're looking for is VirtualHost.

If you're not sure, just use an A record for each domain and subdomain you want to use. That's the simplest and most intuitive way to connect a domain or subdomain with any given server. You can try experimenting with CNAME and other record types once you're comfortable working with DNS.


Top
   
PostPosted: Mon May 18, 2015 7:36 pm 
Offline
Senior Newbie

Joined: Sat May 16, 2015 1:52 pm
Posts: 6
Thanks for the help everyone. I've been pretty much stumped for the past day. I've created an A record for analytics.*mydomain*.com with the IP address of my server. The IP address though resolves into analytics.*mydomain*.com instead of *mydomain*.com.

Here's the pertinent server block file for analytics.*mydomain*.com. Do you guys see any issues with it?

server {
listen 80;
server_name analytics.*mydomain*.com;
return 301 https://analytics.*mydomain*.com$request_uri;
}

server {
listen 443 ssl;
server_name analytics.*mydomain*.com;
root /home/forge/analytics.*mydomain*.com/public;

# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/analytics.*mydomain*.com/8214/server.crt;
ssl_certificate_key /etc/nginx/ssl/analytics.*mydomain*.com/8214/server.k$

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

index index.html index.htm index.php;

charset utf-8;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

access_log off;
error_log /var/log/nginx/analytics.*mydomain*.com-error.log error;

error_page 404 /index.php;

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}


Top
   
PostPosted: Tue May 19, 2015 7:27 am 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
The IP address though resolves into analytics.*mydomain*.com instead of *mydomain*.com.

What do you mean? Domains and subdomains resolve into IP addresses, not the other way around. (Technically, you can make IPs resolve back into domains if you set up "reverse DNS", but that's irrelevant for now.)

If you mean that you get analytics.yourdomain.com when you type your IP address into your browser's address bar, then yes, that's as it should be. When you connect to a server without using a proper hostname, nginx will simply respond with the first "server" block. If analytics.yourdomain.com is the first "server" block, nginx will respond with it. If yourdomain.com is the first "server" block, nginx will respond with it.

People usually set up a dummy "server" block that points to an empty directory and put it at the very top, so that anyone who tries to connect without using a proper hostname will just get a blank page or "404 Not Found" error. This makes it mandatory for everyone to use a proper hostname, such as a domain or subdomain that you explicitly set up.


Top
   
PostPosted: Tue May 19, 2015 12:32 pm 
Offline
Senior Newbie

Joined: Sat May 16, 2015 1:52 pm
Posts: 6
Thank you for your help.

Yes, my issue is that my server's IP resolves to a subdomain; analytics.*mydomain*.com. I don't want this. I would rather have the IP address resolve to *mydomain*.com.

Would it be possible to set up a dummy server block in that case and have it redirect to the domain name of my choice.

I've tried doing this by creating a file called "a" which theoretically Nginx should run before anything else and put in the following code but it doesn't redirect:

server {
listen 80;
server_name *mydomain*.com;
return 301 https://www.*mydomain*.com$request_uri;
}


Top
   
PostPosted: Tue May 19, 2015 10:41 pm 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
The IP -> name mapping is called a PTR record in DNS. This is defined in the "Remote Access" tab of the control panel where you'll see a link for "Reverse DNS".

(This mapping has NO IMPACT on what pages your web server sends out, though).

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group