Configure subdomain on Centos with NGINX

April 8, 2014 3.6k views
I'm trying to add a subdomain to my nginx server, and can't seem to get it working. Here's the config file for my primary server: server { listen 80; server_name; rewrite ^/(.*) permanent; } server { listen 80; server_name; access_log /home/admin/public_html/; error_log /home/admin/public_html/; root /home/admin/public_html/; index index.html; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect false; if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f $request_filename.html) { rewrite (.*) $1.html break; } } } What I would like now is to create a subdomain as following: # ArtWorked // DevCloud server { server_name; root /usr/share/nginx/html/server/devcloud; } Where I'm I going wrong ? And does creating a subdomain on Nginx requires DNS intry such as an A record or a CNAME as there is conflicting information online. Thanks for your help.
3 Answers
Hi Riad,

Could you be a little more explicit about what doesn't work? What error messages are you receiving when trying to access the page?

Take a look at this article for some help with setting up DNS using DigitalOcean's panel:
by Assaf Gordon
Here's some documentation on how to set up and test DNS subdomains with DigitalOcean's DNS panel.
I'm trying to point this subdomain to this path...


When I hit I get the DNS error "You tried to visit, which is not loading."

I've already set an A Record

devcloud in A MY_SERVER_IP.

I've created a fairly simple nginx block as well...

root /usr/share/nginx/html/server/devcloud;
index index.php index.html;

Where I'm I missing ?
It doesn't look like the subdomain was added. Did you add it to Cloudflare's DNS control panel?
Have another answer? Share your knowledge.