Question

Rails 5 application(nginx/puma) with Subdomain is not working even after adding the A Records.

HI, I have recently setup the main domain, for example…domain.com(new droplet) on rails 5 and it got deployed and live successfully. Now I want to use subdomain.domain.com, which is an distinct application(added new droplet) using the same domain name and hence i have also added required entries in the Domain setting as shown below. I have just renamed my subdomain and domain to default names -

in domain.com settings - 2A RECORDS/3NS RECORDS

Hostname                 | Value
-------------            | -------------
subdomain.domain.com     | new_droplet_ip_subdomain
domain.com               | droplet_ip_domain
domain.com               | ns1,ns2,ns3 entires(rented from godaddy) 


also added subdomain.domain.com …settings

(Type)Hostname                   | Value
-------------                    | -------------
(cname)*.subdomain.domain.com    | subdomain.domain.com
(a record)domain.com             | droplet_ip_domain
3 ns records                     | ns1,ns2,ns3 entires(rented from godaddy) 

Moreover there is also a PTR record for -


IPADRESS              |  PTR Record    
-------------------------------------
sub_domain_ip_address | subdomain.domain.

MOrover, there is firewall open to all ports

Type	Protocol	Port Range	Sources	
SSH	TCP	22	All IPv4 All IPv6	More 
HTTP	TCP	80	All IPv4 All IPv6	More 
HTTPS	TCP	443	All IPv4 All IPv6	More 
Custom	TCP	2812	All IPv4 All IPv6	More 

I am not able to understand why its still failing as I cannot see a single log generated in the subdomain_server_ip, where deployment is successful.I am sure, I am making some mistake in the DNS, but what is that.I have also referred DNS details for Digital Ocean but still when I hit subdomain.domain.com on browser, it just keeps loading and stops saying that subdomain.domain.com took too long to respond.

I already have successfully deployed domain.com and its working great. So, 1- do i need to update hosts file?..i did but still the same 2- when I ping - ping subdomain.domain.com, it works and packets are received. 3- NO logs are generated on the subdomain.domain.com server, when I login using ssh user@ip, nginx and puma is working and started, but no logs. 4- On the browser, when I hit subdomain.domain.com, it get subdomain.domain.com took too long to respond.

5- my /etc/nginx/sites-enabled/subdomain.domain.com file looks like shown below: –

  
upstream puma {
  server unix:///home/mike/apps/domain/shared/tmp/sockets/domain-puma.sock;
}

server {
  listen xx.xxx.xx.xxx:80 default deferred;
  server_name www.subdomain.domain.com, subdomain.domain.com;

  root /home/mike/apps/domain/current/public;
  access_log /home/mike/apps/domain/current/log/nginx.access.log;
  error_log /home/mike/apps/domain/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

Can somebody help or give me some ideas as what is missing.


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.

Hello,

If you ping your domain name and you get the IP of your Droplet, this means that your DNS is set up correctly.

I believe that the problem must be with the Nginx configuration.

You could try to do the following:

  • Make sure that Nginx is listening on port 80:
sudo netstat -plant | grep 80

Feel free to share the output here.

  • First run an Nginx config test:
sudo nginx -t
  • If you get a Status OK then try restarting Nginx to make sure that the latest changes that you’ve made are in place:
systemctl restart nginx
  • Finally make sure to check your Nginx error log as well, there should be more information regarding the problem with the timeout.

I would guess that it could be the listen directive that might be causing the problem for you. Can you, as a test, try to change it from:

  listen xx.xxx.xx.xxx:80 default deferred;

To:

    listen 80 default deferred;

Basically that way if you run netstat again it would show you that nginx listens on 0.0.0.0:80 which means that it will accept connections from any IP and you should be able to access the service remotely.

Let me know how it goes! Regards, Bobby