Bom dia. Recentemente fiz o curso Docker aqui na alura e resolvi fazer um desafio para mim. Vou levantar um cluster com .netcore2.1 usando o ngnix para fazer o balancer
Até então beleza, mas estou com problema para fazer funcionar o nginx, quando uso o comando
docker-compose up -d
tenho o seguinte erro
Attaching to nginx
nginx | 2018/06/29 13:24:01 [emerg] 1#1: unknown directive "worker_processes" in /etc/nginx/nginx.conf:1
nginx | nginx: [emerg] unknown directive "worker_processes" in /etc/nginx/nginx.conf:1
nginx exited with code 1
Dockerfile nginx
FROM nginx:latest
MAINTAINER Carlos Smolareck
RUN rm /etc/nginx/conf.d/default.conf
COPY /docker/nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
ENTRYPOINT ["nginx"]
# Parametros extras para o entrypoint
CMD ["-g", "daemon off;"]
nginx.conf
worker_processes 4;
events { worker_connections 1024; }
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
upstream api-netcore {
least_conn;
server node1:8080 weight=10 max_fails=3 fail_timeout=30s;
server node2:8080 weight=10 max_fails=3 fail_timeout=30s;
server node3:8080 weight=10 max_fails=3 fail_timeout=30s;
keepalive 64;
}
server {
listen 80;
server_name 0.0.0.0;
location / {
proxy_pass http://api-netcore;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_cache_bypass $http_upgrade;
}
#return 301 https://$server_name$request_uri;
}
}
docker-compose.yaml
version: '3'
services:
nginx:
build:
dockerfile: ./docker/nginx.dockerfile
context: .
container_name: nginx
ports:
- "8000:80"
networks:
- production-network
depends_on:
- "node1"
- "node2"
- "node3"
node1:
build:
dockerfile: ./docker/api.dockerfile
context: .
container_name: api-1
ports:
- "8080"
networks:
- production-network
node2:
build:
dockerfile: ./docker/api.dockerfile
context: .
container_name: api-2
ports:
- "8080"
networks:
- production-network
node3:
build:
dockerfile: ./docker/api.dockerfile
context: .
container_name: api-3
ports:
- "8080"
networks:
- production-network
networks:
production-network:
driver: bridge
Obs: a parte do .netcore2.1 esta funcionando certinho