DigitalOcean is not redirecting website address to the droplet

July 12, 2019 235 views
DigitalOcean Networking Ubuntu 18.04

After finishing setting up the droplet and website code, I tried to access the website, but all browsers returned 404. I double checked everything to see possible mistakes I made, but everything looks ok.

Entering the droplet IP on the browser returns the nginx default page, meaning that the droplet itself is fine.

Then I concluded that the problem resides in the address redirection process, I’ve deleted the A and AAAA configs and created them again. Still nothing.

DigitalOcean apparently can’t redirect the url request to my droplet.

From what I’ve seen from other questions, some people are having problems related aswell.


ps aux | grep nginx

root      2916  0.0  0.0 141244  7028 ?        Ss   Jul11   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data  2943  0.0  0.0 143832  6336 ?        S    Jul11   0:00 nginx: worker process
www-data  2944  0.0  0.0 143832  6336 ?        S    Jul11   0:00 nginx: worker process
www-data  2945  0.0  0.0 143832  6336 ?        S    Jul11   0:00 nginx: worker process
www-data  2946  0.0  0.0 143832  6336 ?        S    Jul11   0:00 nginx: worker process
root      3121  0.0  0.0  14856  1008 pts/1    S+   00:04   0:00 grep --color=auto nginx

website: advicequest.com
droplet ip: 67.205.160.73

2 comments
  • I have a very similar issue with my droplet (Debian 9, Apache, MariaDB, PHP)

    americanpharoah.ca/john.php returns file not found
    167.99.190.8/john.php serves the info.php webpage (please note, I renamed the info file with my name to make sure I was looking at the correct folder)
    I suspect I am missing something in my config file for the virtual host

    <VirtualHost *:80>
        ServerAdmin admin@americanpharoah.ca
        ServerName americanpharoah.ca
        ServerAlias www.americanpharoah.ca
        <Directory /var/www/americanpharoah.ca/html/racehorses/public>
          Options All
          Require all granted
          Options Indexes FollowSymLinks Includes execCGI
          AllowOverride All
          Order Allow,Deny
          Allow From All
        </Directory>
        DocumentRoot /var/www/americanpharoah.ca/html/racehorses/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =americanpharoah.ca [OR]
    RewriteCond %{SERVER_NAME} =www.americanpharoah.ca
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>
    
  • after checking the CertBot and a few other things, my colleague took a look and we discovered that I had left my previous IP address pointing to the Cloudways IP address I used during a trial.
    just had to comment that line out of the hosts file (C:\Windows\System32\drivers\etc\hosts) on my laptop !

2 Answers

Hello,

Everything seems to be working just fine but you are redirecting your http traffic to https and it looks like that you have not configured Nginx to listen on port 443. You need to install an SSL certificate, sort out your server block for port 443 and the site will start loading as normal.

You can see the redirect simply by running this curl command

curl -IL advicequest.com

The output that you would get would be something like this:

HTTP/1.1 301 Moved Permanently
Server: nginx/1.14.0 (Ubuntu)
Date: Fri, 12 Jul 2019 04:22:45 GMT
Content-Type: text/html
Connection: keep-alive
Location: https://advicequest.com/

curl: (7) Failed to connect to advicequest.com port 443: Connection refused

Hope that this helps!
Bobby

  • But certbot can’t generate an SSL certificate because the http-01 challenge fails.

    Do I need to hard-code the SSL settings into my website nginx config file?

    My output doesn’t return the error (7).

    curl -IL advicequest.com
    
    HTTP/1.1 200 OK
    Server: nginx/1.14.0 (Ubuntu)
    Date: Fri, 12 Jul 2019 19:59:43 GMT
    Content-Type: text/html
    Content-Length: 612
    Last-Modified: Thu, 11 Jul 2019 20:46:15 GMT
    Connection: keep-alive
    ETag: "5d27a017-264"
    Accept-Ranges: bytes
    
    
    

    The output of “ufw status”:

    Status: active
    
    To                         Action      From
    --                         ------      ----
    OpenSSH                    ALLOW       Anywhere                  
    Nginx Full                 ALLOW       Anywhere                  
    OpenSSH (v6)               ALLOW       Anywhere (v6)             
    Nginx Full (v6)            ALLOW       Anywhere (v6)
    

    Chrome now is returning the nginx default page when trying the website address. Firefox still returns the “can’t connect page”. I’m so confused.

    /var/log/nginx/error.log:
     2019/07/12 20:00:38 [notice] 6140#6140: signal process started
    2019/07/12 20:21:53 [alert] 1767#1767: *6 open socket #10 left in connection 5
    2019/07/12 20:21:53 [alert] 1767#1767: aborting
    

I destroyed the droplet and rebuilt everything, setting nginx first and then the website code. It works now.

Have another answer? Share your knowledge.