Redirect Http to Https - Nginx with Let’s Encrypt

Asked

Viewed 153 times

0

At the moment, the domino https://meudominio.com is working, but I can’t redirect http for https using the Let’s Encrypt.

I’m following this tutorial: Link

Below is my configuration:

server {
    listen 80;
    listen 443 ssl;
    server_name meudominio.com www.meudominio.com;


    ssl_certificate /etc/letsencrypt/live/meudominio.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/meudominio.com/privkey.pem;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/ubuntu/project/user;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/project/user/meudominio.sock;
    }
}

server {
    listen 80;
    server_name meudominio.com;
    return 301 https://$host$request_uri;
}
  • Why use two blocks server with the same door?

1 answer

0


I do it differently:

server {
    listen 80;
    server_name meudominio.com;
    rewrite ^(.*)$ https://$host/$1 permanent;
}

I believe if you want to do it this way I think it should be this way:

server {
    listen 80;
    server_name meudominio.com;

    location ~ (.*)$ {
        return 301 https://$host$request_uri;
    }
}

Test ai of give us a feedback.

  • Yes that’s right, I had already solved the problem. Thank you very much.!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.