I have 2 lambda functions wrapped in docker containers and am using docker compose to run them together. One runs on port 9000 the other on port 9001. I am trying to use nginx to allow them to both be reachable on the same port locally. I am able to hit each lambda individually at their respective port in postman at
localhost:9000/2015-03-31/functions/function/invocations
but not at the nginx mapped port.
Here is my default.conf
server {
listen 80;
server_name localhost;
location /user-api/ {
proxy_pass http://127.0.0.1:9000/2015-03-31/functions/function/invocations;
}
location /cart-api/ {
proxy_pass http://127.0.0.1:9001/2015-03-31/functions/function/invocations;
}
}
Here is my docker-compose.yml
version: "3.7"
services:
user-api:
build: ./app/lambdas/user-api
ports:
- 9000:8080
env_file:
- .env
cart-api:
build: ./app/lambdas/cart-api
ports:
- 9001:8080
env_file:
- .env
nginx-proxy:
depends_on:
- user-api
- cart-api
image: nginx:alpine
volumes:
- $PWD/default.conf:/etc/nginx/conf.d/default.conf
networks:
my-network-name:
aliases:
- api-g-way
ports:
- 1234:80
networks:
my-network-name:
Here is the terminal output when I try to access either one
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[+] Running 3/0
⠿ Container my-lambdas-cart-api-1 Created 0.0s
⠿ Container my-lambdas-user-api-1 Created 0.0s
⠿ Container my-lambdas-nginx-proxy-1 Created 0.0s
Attaching to my-lambdas-cart-api-1, my-lambdas-nginx-proxy-1, my-lambdas-user-api-1
my-lambdas-cart-api-1 | 22 Oct 2022 19:20:35,282 [INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)
my-lambdas-user-api-1 | 22 Oct 2022 19:20:35,301 [INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)
my-lambdas-nginx-proxy-1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
my-lambdas-nginx-proxy-1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
my-lambdas-nginx-proxy-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
my-lambdas-nginx-proxy-1 | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
my-lambdas-nginx-proxy-1 | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
my-lambdas-nginx-proxy-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
my-lambdas-nginx-proxy-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
my-lambdas-nginx-proxy-1 | /docker-entrypoint.sh: Configuration complete; ready for start up
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: using the "epoll" event method
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: nginx/1.23.2
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: built by gcc 11.2.1 20220219 (Alpine 11.2.1_git20220219)
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: OS: Linux 5.10.124-linuxkit
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: start worker processes
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: start worker process 29
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: start worker process 30
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: start worker process 31
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: start worker process 32
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:35 [notice] 1#1: start worker process 33
my-lambdas-nginx-proxy-1 | 172.19.0.1 - - [22/Oct/2022:19:20:40 +0000] "POST /user-api HTTP/1.1" 502 157 "-" "PostmanRuntime/7.29.2" "-"
my-lambdas-nginx-proxy-1 | 2022/10/22 19:20:40 [error] 29#29: *1 connect() failed (111: Connection refused) while connecting to upstream, client: XXX.XX.XX.XXX, server: localhost, request: "POST /user-api HTTP/1.1", upstream: "http://127.0.0.1:9000/2015-03-31/functions/function/invocations", host: "127.0.0.1:1234"
It seems to be hitting the correct upstream address but I am getting connection refused. Bear in mind this is my first time using nginx. Any help would be appreciated!
Related
I just doubled my RAM just to check if the error is actually because of RAM, but I don't think so, still failing with below issue after double the RAM
Attaching to nginx
nginx | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
nginx | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx | 2022/11/01 07:18:38 [notice] 1#1: using the "epoll" event method
nginx | 2022/11/01 07:18:38 [notice] 1#1: nginx/1.23.2
nginx | 2022/11/01 07:18:38 [notice] 1#1: built by gcc 11.2.1 20220219 (Alpine 11.2.1_git20220219)
nginx | 2022/11/01 07:18:38 [notice] 1#1: OS: Linux 5.4.0-131-generic
nginx | 2022/11/01 07:18:38 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx | 2022/11/01 07:18:38 [notice] 1#1: start worker processes
nginx | 2022/11/01 07:18:38 [notice] 1#1: start worker process 29
nginx | 2022/11/01 07:18:38 [notice] 1#1: start worker process 30
nginx exited with code 137
compose file:
version: '3.8'
services:
nginx:
container_name: nginx
image: nginx:1.23.2-alpine
restart: always
ports:
- 80:80
- 443:443
volumes:
- /opt/aaa/conf/nginx/:/etc/nginx/conf.d/
- /opt/aaa/letsencrypt:/etc/letsencrypt/
- /var/www/html/.well-known:/code/well-known
- /etc/ssl/dhparam.pem:/etc/ssl/dhparam.pem
- /opt/aaa/website/static:/code/static
- /opt/aaa/install:/opt/install
networks:
- mehere
networks:
personal:
name: mehere
This is happening starting today, after a script just renewed my certs from letsencrypt.
Any idea please?
I'm just silly.
I had a script that removed that container nginx :-)
I'm using docker containers to host a web app. I have three main containers: MySQL, flask and Nginx. The first two work as expected and the latter seems to be working fine as no error is displayed in the docker-compose startup.
Nginx container initialization output:
nginx | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx | 2022/04/07 13:09:13 [notice] 1#1: using the "epoll" event method
nginx | 2022/04/07 13:09:13 [notice] 1#1: nginx/1.21.6
nginx | 2022/04/07 13:09:13 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
nginx | 2022/04/07 13:09:13 [notice] 1#1: OS: Linux 4.19.130-boot2docker
nginx | 2022/04/07 13:09:13 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx | 2022/04/07 13:09:13 [notice] 1#1: start worker processes
nginx | 2022/04/07 13:09:13 [notice] 1#1: start worker process 21
Nginx dockerfile
# Dockerfile-nginx
FROM nginx:latest
# Nginx will listen on this port
# EXPOSE 80
# Remove the default config file that
# /etc/nginx/nginx.conf includes
RUN rm /etc/nginx/conf.d/default.conf
# We copy the requirements file in order to install
# Python dependencies
COPY nginx.conf /etc/nginx/conf.d/
Containers after being deployed and their respective ports:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bffffcfe2f70 sc_server_nginx "/docker-entrypoint.…" 14 seconds ago Up 13 seconds 0.0.0.0:80->80/tcp nginx
a73d958c1407 sc_server_flask "uwsgi app.ini" 9 hours ago Up 9 hours 8080/tcp flask
d273db5f80ef mysql:5.7 "docker-entrypoint.s…" 21 hours ago Up 9 hours (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
I'm new to Nginx server, so I guess it may be a newbie error. I'm trying to redirect all the traffic from my host machine's 80 port to docker's 80 which redirects the traffic to the WSGI container via a socket.
I'm using the following Nginx configuration (nothing close to fancy I guess):
server {
listen 80;
location / {
include uwsgi_params;
uwsgi_pass flask:8080;
}
}
As you can see the server listens at port 80 and redirects all the traffic via the socket uwsgi_pass flask:8080; to the WSGI container that is hosting the app.
However, whenever I type 127.0.0.1:80 or 0.0.0.0:80 in my browser the connection is refused. I have no firewall deployed, so I guess that there is no problem with port 80 being down.
This is my app.ini configuation file, in which the initialization and deployment params are indicated:
[uwsgi]
wsgi-file = wsgi.py
; This is the name of the variable
; in our script that will be called
callable = app
; We use the port 8080 which we will
; then expose on our Dockerfile
socket = :8080
; Set uWSGI to start up 4 workers
processes = 4
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true
Additionally, I also include the docker-compose.yml (I guess it may be helpful):
docker-compose.yml
services:
flask:
build: ./flask
container_name: flask
restart: always
environment:
- APP_NAME=MyFlaskApp
- YOURAPPLICATION_SETTINGS=docker_config.py
expose:
- 8080
depends_on:
mysql:
condition: service_healthy
mysql:
image: mysql:5.7
container_name: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE:
MYSQL_USER:
MYSQL_PASSWORD:
volumes:
- ./db/init.sql:/data/application/init.sql
healthcheck:
test: mysql -u -p --database -e "show tables;"
interval: 3s
retries: 5
start_period: 30s
nginx:
build: ./nginx
container_name: nginx
restart: always
depends_on:
- mysql
- flask
ports:
- "80:80"
Anyone can help?
Update
I've used Wireshark to scan the loopback interface to see the server's response to 0.0.0.0:80 (I suspect there might be some problem with port 80) and I get the following payload:
Update 2:
After deploying the app in EC2 everything seems to be working fine. Thus, it has to be some problem with port 80 at localhost. My machine's OS is macOS Monterrey 12.4 and the system firewall is turned down.
I have server, which is hp t620 with 64gb ssd inside and two 1tb hdd disk in the cover connected by USB 3.0 and configured in RAID 1 (cover has option to configured RAID 1, 0 and JBOD). HDD disk are mounted under /srv/dev-disk-by-uuid-9eac4f7c-81d6-48a7-9a4a-c8f20ceba7b5
It operates under OMV 5.10.
I installed the docker by OMV web GUI in /srv/dev-disk-by-uuid-9eac4f7c-81d6-48a7-9a4a-c8f20ceba7b5/dane_aplikacji/docker. I run on the docker the nextcloud server app from the docker-compose file:
version: '3'
services:
proxy:
image: jwilder/nginx-proxy:alpine
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
container_name: nextcloud-proxy
networks:
- nextcloud_network
ports:
- 88:80
- 444:443
volumes:
- ./proxy/conf.d:/etc/nginx/conf.d:rw
- ./proxy/vhost.d:/etc/nginx/vhost.d:rw
- ./proxy/html:/usr/share/nginx/html:rw
- ./proxy/certs:/etc/nginx/certs:ro
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
environment:
- VIRTUAL_PROTO=https
- VIRTUAL_PORT=444
restart: unless-stopped
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nextcloud-letsencrypt
depends_on:
- proxy
cap_add:
- NET_ADMIN
networks:
- nextcloud_network
environment:
- PUID=998 #change PUID if needed
- PGID=100 #change PGID if needed
- TZ=Europe/Warsaw # change Time Zone if needed
- URL=myurl.duckdns.org
- SUBDOMAINS=www
- VALIDATION=https
- EMAIL=myaccount#gmail.com
volumes:
- ./proxy/certs:/etc/nginx/certs:rw
- ./proxy/vhost.d:/etc/nginx/vhost.d:rw
- ./proxy/html:/usr/share/nginx/html:rw
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: unless-stopped
db:
image: mariadb
command: --skip-innodb-read-only-compressed
container_name: nextcloud-mariadb
networks:
- nextcloud_network
volumes:
- db:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
environment:
- MYSQL_ROOT_PASSWORD= SUPER_PASSWORD
- MYSQL_PASSWORD=SUPER_PASSWORD
- MYSQL_USER=nextcloud
- MYSQL_DATABASE=nextcloud
- MYSQL_HOST=db
restart: unless-stopped
app:
image: nextcloud:latest #ghcr.io/linuxserver/nextcloud
container_name: nextcloud-app
hostname: myurl.duckdns.org
networks:
- nextcloud_network
depends_on:
- letsencrypt
- proxy
- db
volumes:
- nextcloud:/var/www/html:z
- ./app/config:/var/www/html/config
- ./app/custom_apps:/var/www/html/custom_apps
- /srv/dev-disk-by-uuid-9eac4f7c-81d6-48a7-9a4a-c8f20ceba7b5/nextcloud:/var/www/html/data
- ./app/themes:/var/www/html/themes
- /etc/localtime:/etc/localtime:ro
environment:
- TZ=Europe/Warsaw
- VIRTUAL_HOST=myurl.duckdns.org
- LETSENCRYPT_HOST=myurl.duckdns.org:444
- LETSENCRYPT_EMAIL=myaccount#gmail.com
- PHP_MEMORY_LIMIT=20G
- MYSQL_ROOT_PASSWORD=SUPER_PASSWORD
- MYSQL_PASSWORD=SUPER_PASSWORD
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
- NEXTCLOUD_HOSTNAME=myurl.duckdns.org
restart: unless-stopped
news-updater:
image: kr3ssh/nextcloud-news-updater
environment:
- INTERVAL=60
- NEXTCLOUD_URL=http://myurl.duckdns.org:88
- NEXTCLOUD_ADMIN_USER=PAN_ADMIN
- NEXTCLOUD_ADMIN_PASSWORD=SUPER_PASSWORD
restart: always
volumes:
nextcloud:
db:
networks:
nextcloud_network:
When I started to use the server i have only 16gb ssd inside and I had have docker files on the /srv/dev-disk-by-uuid-9eac4f7c-81d6-48a7-9a4a-c8f20ceba7b5/dane_aplikacji/docker but recently I installed 64gb ssd. I have taken OS img and installed it on the 64gb disk by rufus and expand partition. Docker and nextcloud work without no problem. Next I have copied docker file from /srv/dev-disk-by-uuid-9eac4f7c-81d6-48a7-9a4a-c8f20ceba7b5/dane_aplikacji/docker to /var/lib.docker and run docker from there by OMV web GUI. It was bad idea because nextcloud container hasn't worked. On the web page I only see:
Internal Server Error
The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.
In the nextcloud log file I see:
[Sat Jan 15 15:14:11.109982 2022] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.51 (Debian) PHP/8.0.14 configured -- resuming normal operations
[Sat Jan 15 15:14:11.110121 2022] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
ITS.MYI.P - - [15/Jan/2022:15:14:12 +0100] "GET / HTTP/1.1" 500 717 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ITS.MYI.P Safari/537.36 Edg/ITS.MYI.P"
ITS.MYI.P - admin [15/Jan/2022:15:14:38 +0100] "GET /index.php/apps/news/api/v1-2/cleanup/before-update HTTP/1.1" 500 717 "-" "Python-urllib/3.7"
In the nginx log file I see:
Lines
100
Actions
nginx.1 | 2022/01/15 15:14:08 [notice] 24#24: start worker processes
nginx.1 | 2022/01/15 15:14:08 [notice] 24#24: start worker process 30
nginx.1 | 2022/01/15 15:14:08 [notice] 24#24: start worker process 31
nginx.1 | 2022/01/15 15:14:08 [notice] 24#24: start worker process 32
nginx.1 | 2022/01/15 15:14:08 [notice] 24#24: start worker process 33
dockergen.1 | 2022/01/15 15:14:08 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
dockergen.1 | 2022/01/15 15:14:08 Watching docker events
dockergen.1 | 2022/01/15 15:14:08 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
nginx.1 | myurl.duckdns.org ITS.MYI.P - admin [15/Jan/2022:15:14:08 +0100] "GET /index.php/apps/news/api/v1-2/cleanup/before-update HTTP/1.1" 503 190 "-" "Python-urllib/3.7" "-"
dockergen.1 | 2022/01/15 15:14:09 Received event start for container 70f8ad9b1266
dockergen.1 | 2022/01/15 15:14:09 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
nginx.1 | myurl.duckdns.org ITS.MYI.P - - [15/Jan/2022:15:14:09 +0100] "GET / HTTP/1.1" 503 592 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ITS.MYI.P Safari/537.36 Edg/ITS.MYI.P" "-"
dockergen.1 | 2022/01/15 15:14:10 Received event start for container 94b2d83900f4
dockergen.1 | 2022/01/15 15:14:10 Generated '/etc/nginx/conf.d/default.conf' from 10 containers
dockergen.1 | 2022/01/15 15:14:10 Running 'nginx -s reload'
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: signal 1 (SIGHUP) received from 37, reconfiguring
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: reconfiguring
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: using the "epoll" event method
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: start worker processes
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: start worker process 38
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: start worker process 39
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: start worker process 40
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: start worker process 41
nginx.1 | 2022/01/15 15:14:10 [notice] 30#30: gracefully shutting down
nginx.1 | 2022/01/15 15:14:10 [notice] 31#31: gracefully shutting down
nginx.1 | 2022/01/15 15:14:10 [notice] 30#30: exiting
nginx.1 | 2022/01/15 15:14:10 [notice] 32#32: gracefully shutting down
nginx.1 | 2022/01/15 15:14:10 [notice] 32#32: exiting
nginx.1 | 2022/01/15 15:14:10 [notice] 30#30: exit
nginx.1 | 2022/01/15 15:14:10 [notice] 32#32: exit
nginx.1 | 2022/01/15 15:14:10 [notice] 33#33: gracefully shutting down
nginx.1 | 2022/01/15 15:14:10 [notice] 33#33: exiting
nginx.1 | 2022/01/15 15:14:10 [notice] 33#33: exit
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: signal 17 (SIGCHLD) received from 33
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: worker process 33 exited with code 0
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: signal 29 (SIGIO) received
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: signal 17 (SIGCHLD) received from 32
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: worker process 32 exited with code 0
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: signal 29 (SIGIO) received
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: signal 17 (SIGCHLD) received from 30
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: worker process 30 exited with code 0
nginx.1 | 2022/01/15 15:14:10 [notice] 24#24: signal 29 (SIGIO) received
nginx.1 | 2022/01/15 15:14:11 [notice] 31#31: exiting
I try with chmod 775 for /srv/dev-disk-by-uuid-9eac4f7c-81d6-48a7-9a4a-c8f20ceba7b5/nextcloud, /var/www and /var/lib/docker reinstalation apache2 and installation php and effect is the same.
I have a julia app which has been dockerized using below docker file. And,I am running this local app as docker container on port 8080. The goal is to expose this docker app (port 8080) to public using nginx docker container.
I have followed this tutorial: https://www.domysee.com/blogposts/reverse-proxy-nginx-docker-compose and based on the instructions I have created two files, docker-compose.yml and nginx.conf as shown below.
Dockerfile for the local-app:
FROM julia:1.6
RUN apt-get update && apt-get install -y gcc
ENV JULIA_PROJECT #.
WORKDIR /home
ENV VERSION 1
ADD . /home
EXPOSE 8080
ENTRYPOINT ["julia", "-JApp.so", "-t", "auto", "-L", "src/App.jl", "-e", "App.run()"]
Docker-Compose:
version: "3.9"
services:
nginx:
image: nginx:alpine
container_name: production_nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- .:/usr/share/nginx/html
- ./nginx/error.log:/etc/nginx/error_log.log
- ./nginx/cache/:/etc/nginx/cache
- /etc/letsencrypt/:/etc/letsencrypt/
ports:
- 8080:80
- 443:443
local-app:
image: local-app:latest
container_name: production-local-app
expose:
- "8080"
Nginx.conf:
events {
}
http {
error_log /etc/nginx/error_log.log warn;
client_max_body_size 20m;
proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;
server {
server_name app.local.hosting;
location /local-app {
proxy_pass http://localhost:8080;
rewrite ^/local-app(.*)$ $1 break;
}
listen 80;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/app.local.hosting/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.local.hosting/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
}
}
However, running the docker-compose starts two containers, 1 app and 2 nginx, but nginx exits with some error. May I ask, what could be the potential cause of the service failure. Look forward to all the suggestions, thanks in advance!
Update:
Adding the output from terminal upon executing the docker-compose file:
user#user:~/Desktop/App$sudo docker-compose up
Starting production-local-app ... done
Starting production_nginx ... done
Attaching to production_nginx, production-local-app
production_nginx | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
production_nginx | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
production_nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
production_nginx | 10-listen-on-ipv6-by-default.sh: info: IPv6 listen already enabled
production_nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
production_nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
production_nginx | /docker-entrypoint.sh: Configuration complete; ready for start up
production_nginx | 2021/12/05 16:27:03 [emerg] 1#1: open() "/etc/letsencrypt/options-ssl-nginx.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:23
production_nginx | nginx: [emerg] open() "/etc/letsencrypt/options-ssl-nginx.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:23
production_nginx exited with code 1
production-local-app |
production-local-app | Web Server starting at http://localhost:8080 - press Ctrl/Cmd+C to stop the server.
Tying to set up multiple flask API's via Nginx gateway (uwsgi) seems unable to add multiple locations / in the Nginx conf file. The authentication service seems working fine on port 80 but the streaming service always returns 502.
Structure (with docker files)
-authentication - It works fine
-streaming - Gives 502 http://127.0.0.1/devapp/api/v1/home/list
-ngix
Nginx config :
server {
listen 80;
location / {
include uwsgi_params;
uwsgi_pass authentication:8080;
}
location /devapp/ {
include uwsgi_params;
uwsgi_pass streaming:8081;
} }
uwsgi.ini: (for the streaming module)
#Contains uwsgi configurations
[uwsgi]
wsgi-file= run.py
callable = app
socket = :8081
processes = 4
threads = 2
master = true
chomod-socket = 660
vaccum = true
die-on-term = true
module = run
Nginx Log:
docker logs --tail=10 -f nginx
2021/09/13 02:19:51 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/09/13 02:19:51 [notice] 1#1: start worker processes
2021/09/13 02:19:51 [notice] 1#1: start worker process 23
2021/09/13 02:19:51 [notice] 1#1: start worker process 24
2021/09/13 02:19:51 [notice] 1#1: start worker process 25
2021/09/13 02:19:51 [notice] 1#1: start worker process 26
2021/09/13 02:19:51 [notice] 1#1: start worker process 27
2021/09/13 02:19:51 [notice] 1#1: start worker process 28
2021/09/13 02:21:23 [error] 23#23: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.21.0.1, server: , request: "GET /devapp/api/v1/home/list HTTP/1.1", upstream: "uwsgi://172.21.0.3:8081", host: "127.0.0.1"
172.21.0.1 - - [13/Sep/2021:02:21:23 +0000] "GET /devapp/api/v1/home/list HTTP/1.1" 502 157 "-" "PostmanRuntime/7.26.8" "-"