Jsinh
Jsinh

Reputation: 2579

Ngnix configuration redirecting HTTPS to HTTP after setting up SSL

Here is my Nginx configuration for a site. I recently edited it to set up my SSL cert and serve from HTTPS only. Now the HTTP works / opens fine but HTTPS redirects to HTTP

server {
    listen 80;
    listen 443 ssl;
    server_name abc.test.com;

    add_header Strict-Transport-Security "max-age=31536000";

    ssl_certificate /etc/nginx/ssl/nginx.pem;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;

    client_max_body_size 10M;

    location / {
            proxy_pass http://localhost:2368/;
            proxy_redirect off;
            proxy_set_header HOST $host;
            proxy_buffering off;
    }
}

Domain name is replaced with example to keep it simple.

Tried removing listen 80; but did not helped.

Upvotes: 0

Views: 142

Answers (1)

Marten
Marten

Reputation: 117

Can you try this? It redirects HTTP sites to HTTPS.

   server {
            listen 80;
            listen [::]:80;

            server_name abc.test.com;

            return 301 https://$host$request_uri;
    }

    server {
            # SSL configuration
            listen 443 ssl;
            listen [::]:443 ssl;
            server_name abc.test.com;

            ssl_certificate /etc/nginx/ssl/nginx.pem;
            ssl_certificate_key /etc/nginx/ssl/nginx.key;

            add_header Strict-Transport-Security "max-age=31536000";

            client_max_body_size 10M;

            location / {
               proxy_pass http://localhost:2368/;
               proxy_redirect off;
               proxy_set_header HOST $host;
               proxy_buffering off;
            }
    }

Upvotes: 2

Related Questions