Nginx up like orphan containers and not working (521 error)

本小妞迷上赌 提交于 2020-04-30 06:42:05

问题


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.

It is my Dockerfile:

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

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

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;
}
}
}

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:

WARNING: Found orphan containers (core_nginx_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.

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

It is my production.yml:

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

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


回答1:


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

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.



来源:https://stackoverflow.com/questions/61330761/nginx-up-like-orphan-containers-and-not-working-521-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!