Nginx returns 404 error for HTTPS connections - SSL HTTPS Nginx Meteor

September 26, 2017 152 views
Nginx Ubuntu

Hi,

I'm running a Meteor app on a droplet, and I tried to follow this tutorial for setting up ssl and https connections:
https://www.digitalocean.com/community/tutorials/how-to-install-an-ssl-certificate-from-a-commercial-certificate-authority

HTTP connections to bqscorekeeper.com still work, but for HTTPS connections, nginx returns 404 not found.

When I type "nginx -t", this message is returned:
nginx: [warn] conflicting server name "bqscorekeeper.com" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

I'm not sure what to do now. Here are two of my files from /etc/nginx/sites-enabled

bscorekeeper.com.conf:

server {
        listen 80;

        server_name bqscorekeeper.com www.bqscorekeeper.com *.bqscorekeeper.com 104.236.89.47;
        access_log /var/log/nginx/app.dev.access.log;
        error_log /var/log/nginx/app.dev.error.log;
        location / {
                proxy_pass http://104.236.89.47:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header X-Fowarded-For $remote_addr;
        }
}

default:

server {
        listen 80;
        server_name bqscorekeeper.com;
        listen [::]:80 default_server ipv6only=on;

        root /usr/share/nginx/html;
        index index.html index.htm;

        location / {
                try_files $uri $uri/ =404;
        }
}


server {
        listen 443;
        server_name bqscorekeeper.com;


        root /user/share/nginx/html;
        index index.html index.htm;

        ssl on;
        ssl_certificate /root/bqscorekeeper.com.crt;
        ssl_certificate_key /root/bqscorekeeper.com.key;

        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
        location / {
                try_files $uri $uri/ =404;
        }
}
3 Answers

You are setting the same thing twice under http (80)
server_name bqscorekeeper.com;

  • Thanks. I removed it, and now the nginx error is gone, but my site still returns 404 for HTTPS. Do you know how I can fix that?

Yes in the 80 block you need to redirect to the https one.

Have a look at the configuration here to try and see why your https isn't serving or finding the app properly.
https://www.digitalocean.com/community/questions/cannot-configure-https-for-www-subdomain-using-nginx-server-blocks

Have another answer? Share your knowledge.