那是正确的配置吗?试图将htttp重定向到https

时间:2018-12-11 11:24:32

标签: nginx

我有这样的配置,但是它仍然没有从http重定向到https。我应该重新订购还是缺少什​​么?

 server {    
    listen 80;

    server_name www.example.me example.me;
    error_log /var/log/nginx/examplefront.error_log debug; rewrite_log on;
    access_log /var/log/nginx/examplefront.access_log; 


    location / {
      proxy_pass http://exampleme.s3-website.eu-central-1.amazonaws.com;
      proxy_http_version 1.1;
      proxy_set_header Authorization ""; 
      proxy_hide_header Authorization; 
      proxy_set_header X-Forwarded-Proto $scheme; 
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.me/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.me/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    listen 80;
    if ($host = www.example.me) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    if ($host = example.me) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

1 个答案:

答案 0 :(得分:0)

所以我做的是: -我删除了listen 80;行 -将server_name example.me www.example.me添加到具有listen 80;

的块中

似乎nginx甚至需要查看server_name语句才能使用if