代码之家  ›  专栏  ›  技术社区  ›  Tushar

如何在HTTPS服务器上为Django API启用HTTP访问

  •  0
  • Tushar  · 技术社区  · 7 年前

    我有一个运行在服务器上的网站,它将所有HTTP请求重定向到HTTPS,如下所示。我还有一些Django API是服务器提供的(比方说 https://www.example.com/apis/log ).我正在Ubuntu+Nginx上运行Django实现,并使用Let's Encrypt安装了SSL证书。

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

    现在,我想做以下几点:

    0 回复  |  直到 7 年前
        1
  •  1
  •   Shihabudheen K M    7 年前

    在nginx配置中

    server {
        listen 80;
        listen 443 default_server ssl;
    
        # other directives
    }
    

    80-用于http和 443-用于https