【问题标题】:How to redirect http to https in nginx/1.18.0 ubuntu如何在 nginx/1.18.0 ubuntu 中将 http 重定向到 https
【发布时间】:2020-11-04 10:16:37
【问题描述】:

我想将我的域 http://example.com 重定向到 https://example.com

任何人都可以告诉我我做错了什么。

在此先感谢-----------:)

server {
    listen 85;
    listen [::]:85;
    server_name example.com;
    return 302 https://example.com$request_uri;
}

server {
    listen 85 ;
    listen [::]:85 ;
    

    server_name example.com www.example.com; # managed by Certbot

    location /static/ {
        alias /home/shoaib/dir/static/;
    }
    location /media/ {
        alias /home/shoaib/dir/media_root/;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/car.sock;
    }
    

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/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



}

【问题讨论】:

    标签: linux ubuntu nginx https


    【解决方案1】:

    我做了这样的事情:

    return 301 https://$server_name$request_uri;
    

    301 用于永久重定向

    【讨论】:

    • 这不起作用我的域显示“欢迎使用 nginx!”
    【解决方案2】:
    I use this config
    
    server {
        listen 80;
        listen myIP:443;
        server_name www.exemple.fr exemple.fr;
        return 301 https://$server_name$request_uri;
    }
    
    server{
    
       
        listen               80;
        listen               443 ssl ;
        server_name          exemple.fr;
        
        
    
        return 301 https://www.exemple.fr$request_uri;
    }
    

    【讨论】:

      【解决方案3】:

      这不起作用我的域显示“欢迎使用 nginx!”

      尝试使用超级用户重新启动您的 nginx,然后重试:

      service nginx restart
      

      https://phoenixnap.com/kb/nginx-start-stop-restart#htoc-force-restart-nginx

      对于重大的配置更改,您可以强制完全重启 Nginx。这强制关闭整个服务和子流程,并且 重新启动整个包。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-14
        • 2011-03-29
        • 2018-01-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-23
        • 2014-10-11
        相关资源
        最近更新 更多