I have a new site devsmkapp.com that will only load the Http (Port 80), but not my SSL (Port 443). It was built with Django and is running on a DO Ubuntu 18.04 droplet. It was configured manually with gunicorn, as in, it’s not a one-click install. But it’s still a basic setup.

sites-available/default

server {
        listen [::]:80 ipv6only=on;
        server_name _;

        return 301 https://$host$request_uri;
        # keepalive_timeout 10;
}
server {
        # SSL configuration
        #
        listen [::]:443 ipv6only=on default_server;

        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;
        keepalive_timeout 10;
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        ssl on;
        server_name devsmkapp.com www.devsmkapp.com;
        ssl_certificate "/home/djangoadmin/server.crt";
        ssl_certificate_key "/home/djangoadmin/devsmkapp.com.key";

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers HIGH:!aNULL:!MD5;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

sites-enabled/default

server {
        listen [::]:80 ipv6only=on;
        server_name _;

        return 301 https://$host$request_uri;
        # keepalive_timeout 10;
}
server {
        # SSL configuration
        #
        listen [::]:443 ipv6only=on default_server;

        server_name devsmkapp.com www.devsmkapp.com;
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
         #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;
        keepalive_timeout 10;
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        ssl on;
        server_name devsmkapp.com www.devsmkapp.com;
        ssl_certificate "/home/djangoadmin/server.crt";
        ssl_certificate_key "/home/djangoadmin/devsmkapp.com.key";

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers HIGH:!aNULL:!MD5;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
         #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        client_max_body_size 20;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml appli$

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        # include /etc/nginx/sites-enabled/*;
        include /etc/nginx/sites-available/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

My site http://devsmkapp.com loads just fine, however, it does not redirect to htpps://devsmkapp.com as I have it configured to as well as https://devsmkapp.com not getting past the “Welcome to NGINX” screen saying further configuration is required. If I run sudo nginx I get:

nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

I have already tried sudo fuser -k 443/tcp(also 80/tcp) with sudo service nginx restart to no avail. Any help is appreciated.

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

Hi there @DevSMK,

From the error that you’ve shared, it looks like that you might have either another service running on the same port or a duplicate hostname defined in your server blocks.

I would recommend first checking what services you have listening on port 80:

  • netstat -plant

And I will also recommend checking your /etc/nginx/sites-enabled folder for any server blocks or hostnames.

Also if you run an Nginx config test do you get any errors:

  • sudo nginx -t

Regards,
Bobby

  • sudo netstat -plant

    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3939/nginx: master
    tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      623/systemd-resolve
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      888/sshd
    tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      26978/postgres
    tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      3939/nginx: master
    tcp        0      0 157.245.246.154:80      176.113.115.214:36388   TIME_WAIT   -
    tcp        0    340 157.245.246.154:22      67.87.22.204:62587      ESTABLISHED 5097/sshd: scott [p
    tcp        0   1121 157.245.246.154:22      222.186.42.155:18930    ESTABLISHED 6499/sshd: [accepte
    tcp6       0      0 :::80                   :::*                    LISTEN      3939/nginx: master
    tcp6       0      0 :::22                   :::*                    LISTEN      888/sshd
    

    I was able to figure it out. Nginx was configured correctly, but there was a typo in the A DNS record with my host. So that explains why the page showed Nginx as appropriately loaded, but wouldn’t spit back out anything that Gunicorn was throwing at it. Thanks for your help.

Submit an Answer