Nginx像孤立容器一样向上运行,并且不起作用(521错误) [英] Nginx up like orphan containers and not working (521 error)

查看:543
本文介绍了Nginx像孤立容器一样向上运行,并且不起作用(521错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有docker-compose的容器Nginx,但是它的配置错误.当我将域链接到8000端口时,出现521错误.

I am using a container Nginx with docker-compose, but It have a bad configuration. When I link the domain to 8000 port I have a 521 error.

这是我的Dockerfile:

It is my Dockerfile:

 FROM nginx
 COPY nginx.conf /etc/nginx/nginx.conf

我使用了nginx-alpine,但是如果没有alpine python,它就无法工作,而且我不得不更改它,因为Pandas无法与alpine一起工作.

I used nginx-alpine, but it not working without alpine python, and I had to change it because Pandas not working with alpine.

所以,我的nginx.conf是:

So, my nginx.conf is:

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
 worker_connections  1024;  ## Default: 1024, increase if you have lots of clients
}

http {
 include       /etc/nginx/mime.types;
 # fallback in case we can't determine a type
 default_type  application/octet-stream;

 log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 '$status $body_bytes_sent "$http_referer" '
 '"$http_user_agent" "$http_x_forwarded_for"';

 access_log  /var/log/nginx/access.log  main;

 sendfile        on;
 #tcp_nopush     on;

 keepalive_timeout  65;

 upstream app {
    server django:5000;
 }

server {
# use 'listen 80 deferred;' for Linux
# use 'listen 80 accept_filter=httpready;' for FreeBSD
listen 5000;
charset utf-8;

# Handle noisy favicon.ico messages in nginx
 location = /favicon.ico {
    return 204;
    access_log     off;
    log_not_found  off;
}

 location / {
    # checks for static file, if not found proxy to app
    try_files $uri @proxy_to_app;
}

# django app
 location @proxy_to_app {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forward-Proto http;
    proxy_set_header X-Nginx-Proxy true;
    proxy_temp_file_write_size 64k;
    proxy_connect_timeout 10080s;
    proxy_send_timeout 10080;
    proxy_read_timeout 10080;
    proxy_buffer_size 64k;
    proxy_buffers 16 32k;
    proxy_busy_buffers_size 64k;
    proxy_redirect off;
    proxy_request_buffering off;
    proxy_buffering off;
    proxy_pass http://app;
}
}
}

在构建和启动应用程序时,未显示任何错误,并提示"docker-compose ps",就像照片一样,但有时会消失,并且如果我尝试对某个容器执行某些操作,它的响应是:

When I build and up my application, not show any error, and I tip "docker-compose ps" it appear, like the photo, but in some time it disappear, and if I try to do some action with some container, it response:

警告:找到此项目的孤立容器(core_nginx_1).如果您在撰写文件中删除或重命名了此服务,则可以使用--remove-orphans标志运行此命令以对其进行清理.

我尝试使用COMPOSE_PROJECT_NAME = CORE制作一个.env,但仍然无法正常工作.

I tried to make a .env with COMPOSE_PROJECT_NAME=CORE but not working anyway.

这是我的production.yml:

It is my production.yml:

nginx:
  build: ./compose/production/nginx
  image: core_production_nginx
  ports:
  - 80:80
  depends_on:
  - django

我尝试添加80:5000,但它给我一个错误.

I tried to add 80:5000 but it response me a error.

推荐答案

当容器disappeared表示其关闭时.您可以使用命令docker ps -a看到所有向上和向下的容器.您将在这里找到消失的容器

When your container disappeared that means that it down. You can see all containers, upped and down, with command docker ps -a. You will find your disappeared container here

使用命令docker ps时,您永远不会看到任何错误.此命令仅向您显示正在工作的容器.如果要查看容器内部的错误,应使用命令docker logs <container name>. 而当您的容器disappeared意味着它关闭了.您可以使用命令docker ps -a看到所有向上和向下的容器.您将在这里找到消失的容器.您应该使用docker logs,您将看到为什么该容器关闭.

When you use command docker ps you never see any errors. This command show you only working containers. If you want to see errors inside the container, you should use command docker logs <container name>. And when your container disappeared that means that it down. You can see all containers, upped and down, with command docker ps -a. You will find your disappeared container here. You should use docker logs and you will see why this container down.

这篇关于Nginx像孤立容器一样向上运行,并且不起作用(521错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆