简体   繁体   English

Docker-Django-Nginx 与 http/https 的问题

[英]Docker-Django-Nginx problem with http/https

I'm trying to test a setup in Docker. A web server running a python application, and I want to add an Nginx service to serve it.我正在尝试测试 Docker 中的设置。运行 python 应用程序的 web 服务器,我想添加 Nginx 服务来为其提供服务。 The result I am getting is "400 bad request" error我得到的结果是“400 错误请求”错误

In the Nginx container I do these tests with curl and wget, and these are the results: WGET在 Nginx 容器中,我使用 curl 和 wget 进行了这些测试,结果如下:WGET

root@b301fc0bb378:/# wget http://web_python:8000
--2022-12-05 19:01:06--  http://web_python:8000/
Resolving web_python (web_python)... 172.23.0.3
Connecting to web_python (web_python)|172.23.0.3|:8000... connected.
HTTP request sent, awaiting response... 400 Bad Request
2022-12-05 19:01:06 ERROR 400: Bad Request.`

CURL CURL

root@b301fc0bb378:/# curl http://web_python:8000

<!doctype html>
<html lang="en">
<head>
  <title>Bad Request (400)</title>
</head>
<body>
  <h1>Bad Request (400)</h1><p></p>
</body>
</html>

The Python container responds this: ` Python 容器响应如下:`

[05/Dec/2022 13:34:58] You're accessing the development server over HTTPS, but it only supports HTTP.

This is my nginx.conf: `这是我的 nginx.conf:`

upstream web_python {
    server web_python:8000;
}

server {

    listen 80;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_pass http://web_python;
    }

}

` `

I do not understand why the requests are confused, if my configurations are in http, it is the development phase.我不明白为什么请求会混淆,如果我的配置是http,那就是开发阶段。 Thank you...谢谢...

The Nginx -> Python connection is HTTPS because you have Nginx -> Python 连接是 HTTPS 因为你有

proxy_pass https://web_python;

in your nginx config.在您的 nginx 配置中。

Change it to改成

proxy_pass http://web_python;

to have nginx talk to python over HTTP.让 nginx 通过 HTTP 与 python 通话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM