DigitalOcean – Fix NGINX Server Port 80 Refused on Ubuntu

digital-oceannginxUbuntu

I am having a really annoying issue with my digitalocean droplet running nginx as my web server. UFW is disabled on it and HTTPS does work, but HTTP using CURL on my mac at home gives me connection refused (port 80)…

Here is my configuration for nginx:

# return 301 https://$host$request_uri;
server {
        listen 80;
        server_name creepinson.xyz www.creepinson.xyz;
        location / {
                return 301 https://$server_name$request_uri;
        }
}

# https
server {
        root /var/www/html;
        server_name creepinson.xyz www.creepinson.xyz;
        index index.php index.html index.htm index.nginx-debian.html;
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
         }

        location / {
            try_files $uri $uri/ $uri.php;
        }
        listen 443 ssl;
        ssl_certificate /etc/letsencrypt/live/creepinson.xyz/fullchain.pem; # m$
        ssl_certificate_key /etc/letsencrypt/live/creepinson.xyz/privkey.pem; #$
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

I am also using cloudflare for my domain. I tried using my ip and it gave me port 80 refused but on cloudflare it says 521. I have tried disabling UFW (firewall), resetting IPTables… And it also works perfectly on port 80 when I SSH into the VPS and run curl -v localhost
but when I run curl from anywhere else it doesn't work, only https works. I just have no idea what the heck is wrong with my server. I also ran netstat -lntp | grep 80
and it results in the following:

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      8538/nginx: master

Thanks.

Best Answer

I solved it by disabling cloudflare temporarily and then re-enabling it... I don't why it worked but it works :)