Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
没有针对gunicorn固定烧瓶应用程序的NGINX重定向-NGINX+;Docker&x2B;烧瓶+;古尼科恩_Docker_Nginx_Flask_Docker Compose - Fatal编程技术网

没有针对gunicorn固定烧瓶应用程序的NGINX重定向-NGINX+;Docker&x2B;烧瓶+;古尼科恩

没有针对gunicorn固定烧瓶应用程序的NGINX重定向-NGINX+;Docker&x2B;烧瓶+;古尼科恩,docker,nginx,flask,docker-compose,Docker,Nginx,Flask,Docker Compose,我试图通过几篇教程来理解如何使用Nginx+Docker+Flask+Gunicorn包,但我很难运行一个最小的产品 根据本教程,我使用docker compose文件中的两个服务(即flask_应用程序和nginx服务)运行了一个“hello world”显示 我的问题如下: 我没有在停靠的nginx服务中设置我的HTTPS配置(我正在尝试使用Certbot/Letsencrypt)。因此,我正在尝试为nginx安装一个非停靠的install+config,但当我删除停靠的nginx并直接在服

我试图通过几篇教程来理解如何使用Nginx+Docker+Flask+Gunicorn包,但我很难运行一个最小的产品

根据本教程,我使用docker compose文件中的两个服务(即flask_应用程序和nginx服务)运行了一个“hello world”显示

我的问题如下: 我没有在停靠的nginx服务中设置我的HTTPS配置(我正在尝试使用Certbot/Letsencrypt)。因此,我正在尝试为nginx安装一个非停靠的install+config,但当我删除停靠的nginx并直接在服务器上使用正常的nginx安装时,我陷入了“欢迎使用nginx”的困境

有人能帮我将“普通”NGINX连接到容器化烧瓶应用程序(使用gunicorn)吗? 这是第一次尝试所有这些(webhosting、docker、SSL证书、NGINX等),所以在多次尝试之后,我有点迷路了:)

我的简单应用程序:

Dockerfile

app.py

wsgi.py

requirements.txt

简化的docker-compose.yml,删除了nginx服务(这是与上述tuto的工作结果的关键区别)

最后是nginx配置,它以前是容器化的,由docker compose的nginx服务使用,现在直接在我的服务器上

/etc/nginx/conf.d/project.conf

server {

    listen 80;
    server_name my_IP_address;

    location / {
        proxy_pass http://0.0.0.0:8000;

        # Do not change this
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /static {
        rewrite ^/static(.*) /$1 break;
        root /static;
    }
}
主要思想是能够在nginx conf中轻松地使用certbot,因为我没有在容器中实现它

我尝试了几件事:

  • 捕捉关键点差异的其他一些教程
  • 更改服务器名称(IP,mywebsite.com;)和代理传递(proxy,IP,mywebsite.com;等等)
  • 使用来自web的多个配置模板文件,更改我认为必须更改的内容
我对上述工作方式的理解是:

  • NGINX听我的IP:80
  • 重定向到内部0.0.0.0:8000
  • 它是gunicorn,作为wsgi serveur运行,在一个容器中提供flask应用程序(而不是flask服务器,不是prod-prod-proof)(我应该使用容器的IP进行重定向吗?)
  • NGINX和容器似乎运行平稳:
    • 对于无错误的NGINX NGINX重新加载、NGINX-t等
    • 对于Web服务器:和docker编写日志-f
这也是我第一次打电话来这里,所以我希望我做得很好。感谢阅读:)

PS:如果这是有用的:因为我正在尝试建立一个“生产”环境,这个实验不是在我的计算机上进行的,而是在我为测试租用的远程服务器(ubuntu)上进行的。这可能会对网络方面产生影响

from flask import Flask

server = Flask(__name__)

@server.route('/')
def hello_world():
    return 'hello world!'
from app import server

if __name__ == "__main__":
    server.run(host='0.0.0.0', port=8000)
flask
gunicorn
version: '3'

services:
  flask_app:
    container_name: flask_app
    restart: always
    build: ./flask_app
    ports:
      - "8000:8000"
    command: gunicorn -w 1 -b 0.0.0.0:8000 wsgi:server
  
server {

    listen 80;
    server_name my_IP_address;

    location / {
        proxy_pass http://0.0.0.0:8000;

        # Do not change this
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /static {
        rewrite ^/static(.*) /$1 break;
        root /static;
    }
}
flask_app    | [2021-05-19 10:51:19 +0000] [1] [INFO] Starting gunicorn 20.1.0
flask_app    | [2021-05-19 10:51:19 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
flask_app    | [2021-05-19 10:51:19 +0000] [1] [INFO] Using worker: sync
flask_app    | [2021-05-19 10:51:19 +0000] [8] [INFO] Booting worker with pid: 8