Question

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

Posted February 6, 2020 1.4k views
Ruby on RailsNginx

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 subdomainserverip, 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.

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.

×
1 answer

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

  • Hey Bobby,
    Thanks for the helping hand.However, there is no major change.Let me share the steps that I took after your message....

    – When I ping…

    PING icms.technast.com (68.183.86.169) 56(84) bytes of data.
    --- icms.technast.com ping statistics ---
    79 packets transmitted, 0 received, 100% packet loss, time 79876ms
    
    

    – When I checked port 80

    mike@ICMS:~$ sudo netstat -plant | grep 80
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2079/nginx: master  
    tcp6       0      0 :::80     
    

    – sudo nginx -t - always returns OK, even if delete all links from sites-*/, it still gives OK.

    – I Updated nginx server block listen 80 default deferred;,
    still no changes.

    – Morever, my log/production.log…nginx.error.log…nginx.access.log..puma.access.log and puma.error.log are blank, since day one.

    Let me know if this was helpful and kindly guide me more.
    I have updated my dns settings..Sharing below -

    technast.com - WORKING
    
    DNS records
    Type    Hostname    Value   TTL (seconds)   
    CNAME   
    *.icms.technast.com Copy    is an alias of 
    icms.technast.com 
    A   
    
    icms.technast.com Copy  directs to 
    68.183.86.169
    A   
    
    technast.com Copy   directs to 
    157.230.241.
    NS  
    
    technast.com Copy   directs to 
    ns1.digitalocean.com 
    NS  
    
    technast.comCopy    directs to 
    ns2.digitalocean.com.Copy   
    1800 Copy   More 
    NS  
    
    technast.comCopy    directs to 
    ns3.digitalocean.com
    
    
    icms.technast.com - NOT WORKING
    
    *.icms.technast.com Copy    is an alias of 
    icms.technast.com.
    A   
    
    icms.technast.com Copy  directs to 
    68.183.86.169
    
    NS  
    icms.technast.com Copy  directs to 
    ns2.digitalocean.com
    
    NS  
    icms.technast.com Copy  directs to 
    ns3.digitalocean.com
    
    NS  
    icms.technast.com Copy  directs to 
    ns1.digitalocean.com 
    
    
    
    • Hi @Milind1011,

      It looks like that when you ping the domain name you get 100% packet loss. This would make me think that either your A record might not be matching your Droplet’s IP address or that your firewall is blocking all of the traffic.

      What I could suggest first is to try and telnet on port 80 from your PC to your Droplet’s IP to make sure that the Nginx instance is actually reachable:

      telnet your_dropet_ip_address 80
      

      Also, I would recommend double-checking your DNS records and making sure that the A record for your subdomain matches the IP of your Droplet.

      One last suggestion would be, do not add your subdomain name as a separate domain name in your DigitalOcean Domain names control, but instead add the A record and the CNAME records for the subdomain name under your main domain’s DNS zone.

      Let me know how it goes!
      Regards,
      Bobby

      • Thanks Bobby, Due to some time contraint, I have decided to use the same domain to deploy the code.However, i will come back later to inquire about this issue again…and I am sure its something related to DNS settings, as you have mentioned.

        Once again..Thank you.

Submit an Answer