【问题标题】:How to enable HTTP access for Django APIs on HTTPS server如何在 HTTPS 服务器上为 Django API 启用 HTTP 访问
【发布时间】:2019-06-18 03:46:29
【问题描述】:

我有一个在服务器上运行的网站,它将所有 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
}

现在,我想做以下事情:

【问题讨论】:

  • nginx 配置为在HTTP 上服务api

标签: django ssl django-rest-framework


【解决方案1】:

在你的 nginx 配置中

server {
    listen 80;
    listen 443 default_server ssl;

    # other directives
}

80 - 用于 http 和 443 - 用于https

【讨论】:

    猜你喜欢
    • 2018-01-30
    • 2014-03-24
    • 2014-10-17
    • 1970-01-01
    • 2011-11-01
    • 2021-10-29
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多