首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“欢迎来到Nginx!”-Docker-撰写,使用uWSGI,酒瓶,nginx

“欢迎来到Nginx!”-Docker-撰写,使用uWSGI,酒瓶,nginx
EN

Stack Overflow用户
提问于 2020-11-16 22:12:51
回答 1查看 2.1K关注 0票数 4

我的问题:

我使用的是Ubuntu18.04和一个基于坞的解决方案,它有两个Docker映像,一个用于处理Python/uWSGI一个用于NGINX反向代理。无论我更改了什么,WSGI似乎总是无法检测到我的默认应用程序。每当我运行docker-compose up并导航到localhost:5000时,都会得到上述默认启动。

完整的程序似乎在我们的CentOS 7机器上工作。然而,当我试图在Ubuntu测试机器上执行它时,我只能得到“欢迎来到NGINX!”页面。

目录结构:

代码语言:javascript
复制
 /app
  - app.conf
  - app.ini
  - app.py
  - docker-compose.py
  - Dockerfile-flask
  - Dockerfile-nginx
  - requirements.txt
  /templates

(所有代码片段都已简化,以帮助隔离问题)

下面是我的码头跟踪的一个例子:

clocker_flask_1

代码语言:javascript
复制
[uWSGI] getting INI configuration from app.ini
current working directory: /app
detected binary path: /usr/local/bin/uwsgi
uwsgi socket 0 bound to TCP address 0.0.0.0:5000 fd 3
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x558072010e70 pid: 1 (default app)

clocker_nginx_1

代码语言:javascript
复制
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up

,这是我的船坞-compose.yaml。

代码语言:javascript
复制
# docker-compose.yml
version: '3'
services:
  
  flask:
    image: webapp-flask
    build:
      context: .
      dockerfile: Dockerfile-flask
    volumes:
      - "./:/app:z"
      - "/etc/localtime:/etc/localtime:ro"
    environment:
      - "EXTERNAL_IP=${EXTERNAL_IP}"

  nginx:
    image: webapp-nginx
    build:
      context: .
      dockerfile: Dockerfile-nginx
    ports:
      - 5000:80
    depends_on:
      - flask

Dockerfile-flask:

代码语言:javascript
复制
FROM python:3
ENV APP /app
RUN mkdir $APP
WORKDIR $APP
EXPOSE 5000
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD [ "uwsgi", "--ini", "app.ini" ]

Dockerfile-nginx

代码语言:javascript
复制
FROM nginx:latest
EXPOSE 80
COPY app.conf /etc/nginx/conf.d

app.conf

代码语言:javascript
复制
server {
    listen 80;
    root /usr/share/nginx/html;
    location / { try_files $uri @app; }
    location @app {
        include uwsgi_params;
        uwsgi_pass flask:5000;
    }
}

app.py

代码语言:javascript
复制
# Home bit
@application.route('/')
@application.route('/home', methods=["GET", "POST"])
def home():
    return render_template(
        'index.html',
        er = er
    )

if __name__ == "__main__":
    application.run(host='0.0.0.0')

app.ini

代码语言:javascript
复制
[uwsgi]
protocol = uwsgi
module = app
callable = application
master = true
processes = 2
threads = 2
socket = 0.0.0.0:5000
vacuum = true   
die-on-term = true
max-requests = 1000
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-17 03:56:21

nginx映像附带一个主配置文件/etc/nginx/nginx.conf,它加载conf.d文件夹中的每个conf文件--包括您在本例中的死敌股票/etc/nginx/conf.d/default.conf。它的内容如下(为了简洁而修剪了一点):

代码语言:javascript
复制
server {
  listen 80;
  server_name localhost;

  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
  }
}

因此,您的app.conf和此配置都是活动的。但是,这个默认选项获胜的原因是因为它拥有(而您的)缺少的server_name指令--当您按下localhost:5000时,nginx基于主机名进行匹配,并将请求发送到那里。

要轻松地修复这个问题,只需在Dockerfile-nginx中删除该文件:

代码语言:javascript
复制
RUN rm /etc/nginx/conf.d/default.conf
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64866489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档