gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:56 25 4
gpt4 key购买 nike

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

server {
listen 80;
listen 443 default_server ssl;

# other directives
}

80 - 用于 http 和443 - 对于 https

关于django - 如何在 HTTPS 服务器上为 Django API 启用 HTTP 访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56641495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com