hello guyz i am enabling multi-instance thing in the moqui-frmawork and for that i am using jwilder/nginx-proxy (nginx + docker-gen) for running multiple instance on the (instance->ip with same port) and internally nginx-proxy will pass or round-robin the request to the container (in which moqui-server is running). and all containers are in same network of type bridge and this has to work
1)docker-gen will listen for each event of creation/start/die container req and according to that request it will manipulate the template file nginx etc/nginx/conf.d/default.conf and here docker-gen added mapping for each instance/container proxy pass request.
/etc/nginx/conf.d# cat default.conf
# nginx-proxy version : 1.0.1-6-gc4ad18f
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
default $http_x_forwarded_proto;
'' $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
default $http_x_forwarded_port;
'' $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
default upgrade;
'' close;
}
# Apply fix for very long server names
server_names_hash_bucket_size 128;
# Default dhparam
ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
# Set appropriate X-Forwarded-Ssl header based on $proxy_x_forwarded_proto
map $proxy_x_forwarded_proto $proxy_x_forwarded_ssl {
default off;
https on;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss t
ext/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$upstream_addr"';
access_log off;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE
-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SH
A384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA';
ssl_prefer_server_ciphers on;
error_log /dev/stderr;
resolver 127.0.0.11;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
proxy_set_header X-Original-URI $request_uri;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
server_name _; # This is just an invalid value which will never trigger on a real hostname.
server_tokens off;
listen 80;
access_log /var/log/nginx/access.log vhost;
return 503;
}
# moqui.local
upstream moqui.local {
## Can be connected with "moqui_default" network
# moqui_local
server 172.18.0.3:80;
}
server {
server_name moqui.local;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
# Do not HTTPS redirect Let'sEncrypt ACME challenge
location ^~ /.well-known/acme-challenge/ {
auth_basic off;
auth_request off;
allow all;
root /usr/share/nginx/html;
try_files $uri =404;
break;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
server_name moqui.local;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/nginx/certs/moqui.local.crt;
ssl_certificate_key /etc/nginx/certs/moqui.local.key;
ssl_dhparam /etc/nginx/certs/moqui.local.dhparam.pem;
add_header Strict-Transport-Security "max-age=31536000" always;
location / {
proxy_pass http://moqui.local;
}
}
root@rohit:/home/rohit/work/sandbox/moqui-framework/docker# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
d68a9ec142f9 nginxproxy/nginx-proxy "/app/docker-entrypo…" 59 minutes ago Up 59 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443
/tcp nginx-proxy
88ce3a30fdce moqui "java -cp . MoquiSta…" 15 hours ago Up 14 hours (healthy) 80/tcp, 5701/tcp, 9200/tcp, 9300/tcp
moqui_local
66f5d7e6eae9 mysql:8.0 "docker-entrypoint.s…" 2 days ago Up 21 hours 33060/tcp, 127.0.0.1:3308->3306/tcp
moqui-database
root@rohit:/home/rohit/work/sandbox/moqui-framework/docker#
Log status of Nginx-Proxy
docker logs nginx-proxy
Info: running nginx-proxy version 1.0.1-6-gc4ad18f
Setting up DH Parameters..
forego | starting dockergen.1 on port 5000
forego | starting nginx.1 on port 5100
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: using the "epoll" event method
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: nginx/1.21.6
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: OS: Linux 5.14.0-1051-oem
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker processes
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 25
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 26
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 27
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 28
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 29
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 30
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 31
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 32
dockergen.1 | 2022/09/11 06:45:35 Generated '/etc/nginx/conf.d/default.conf' from 3 containers
dockergen.1 | 2022/09/11 06:45:35 Running 'nginx -s reload'
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 1 (SIGHUP) received from 34, reconfiguring
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: reconfiguring
dockergen.1 | 2022/09/11 06:45:35 Watching docker events
nginx.1 | 2022/09/11 06:45:35 [warn] 20#20: could not build optimal proxy_headers_hash, you should increase either proxy_headers_hash_max_
size: 512 or proxy_headers_hash_bucket_size: 64; ignoring proxy_headers_hash_bucket_size
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: using the "epoll" event method
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker processes
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 39
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 40
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 41
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 42
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 43
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 44
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 45
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: start worker process 46
dockergen.1 | 2022/09/11 06:45:35 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
nginx.1 | 2022/09/11 06:45:35 [notice] 25#25: gracefully shutting down
nginx.1 | 2022/09/11 06:45:35 [notice] 26#26: gracefully shutting down
nginx.1 | 2022/09/11 06:45:35 [notice] 27#27: gracefully shutting down
nginx.1 | 2022/09/11 06:45:35 [notice] 28#28: gracefully shutting down
nginx.1 | 2022/09/11 06:45:35 [notice] 29#29: gracefully shutting down
nginx.1 | 2022/09/11 06:45:35 [notice] 30#30: gracefully shutting down
nginx.1 | 2022/09/11 06:45:35 [notice] 31#31: gracefully shutting down
nginx.1 | 2022/09/11 06:45:35 [notice] 32#32: gracefully shutting down
nginx.1 | 2022/09/11 06:45:35 [notice] 29#29: exiting
nginx.1 | 2022/09/11 06:45:35 [notice] 27#27: exiting
nginx.1 | 2022/09/11 06:45:35 [notice] 28#28: exiting
nginx.1 | 2022/09/11 06:45:35 [notice] 26#26: exiting
nginx.1 | 2022/09/11 06:45:35 [notice] 25#25: exiting
nginx.1 | 2022/09/11 06:45:35 [notice] 30#30: exiting
nginx.1 | 2022/09/11 06:45:35 [notice] 32#32: exiting
nginx.1 | 2022/09/11 06:45:35 [notice] 31#31: exiting
nginx.1 | 2022/09/11 06:45:35 [notice] 29#29: exit
nginx.1 | 2022/09/11 06:45:35 [notice] 30#30: exit
nginx.1 | 2022/09/11 06:45:35 [notice] 27#27: exit
nginx.1 | 2022/09/11 06:45:35 [notice] 25#25: exit
nginx.1 | 2022/09/11 06:45:35 [notice] 32#32: exit
nginx.1 | 2022/09/11 06:45:35 [notice] 28#28: exit
nginx.1 | 2022/09/11 06:45:35 [notice] 26#26: exit
nginx.1 | 2022/09/11 06:45:35 [notice] 31#31: exit
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 17 (SIGCHLD) received from 29
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: worker process 29 exited with code 0
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: worker process 26 exited with code 0
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 29 (SIGIO) received
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 17 (SIGCHLD) received from 26
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: worker process 28 exited with code 0
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: worker process 30 exited with code 0
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 29 (SIGIO) received
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 17 (SIGCHLD) received from 31
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: worker process 31 exited with code 0
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 29 (SIGIO) received
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 17 (SIGCHLD) received from 32
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: worker process 32 exited with code 0
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 29 (SIGIO) received
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 17 (SIGCHLD) received from 27
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: worker process 27 exited with code 0
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 29 (SIGIO) received
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 17 (SIGCHLD) received from 25
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: worker process 25 exited with code 0
nginx.1 | 2022/09/11 06:45:35 [notice] 20#20: signal 29 (SIGIO) received
nginx.1 | 0.0.0.0 172.18.0.1 - - [11/Sep/2022:06:46:10 +0000] "GET / HTTP/1.1" 503 592 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53
7.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" "-"
nginx.1 | 0.0.0.0 172.18.0.1 - - [11/Sep/2022:06:46:10 +0000] "GET /favicon.ico HTTP/1.1" 503 592 "http://0.0.0.0/" "Mozilla/5.0 (X11; Lin
ux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" "-"
nginx.1 | localhost 172.18.0.1 - - [11/Sep/2022:07:16:37 +0000] "GET / HTTP/1.1" 503 592 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/
537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" "-"
nginx.1 | localhost 172.18.0.1 - - [11/Sep/2022:07:16:38 +0000] "GET /favicon.ico HTTP/1.1" 503 592 "http://localhost/" "Mozilla/5.0 (X11;
Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" "-"
nginx.1 | localhost 172.18.0.1 - - [11/Sep/2022:07:17:35 +0000] "GET / HTTP/1.1" 503 592 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/
537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" "-"
nginx.1 | localhost 172.18.0.1 - - [11/Sep/2022:07:17:35 +0000] "GET /favicon.ico HTTP/1.1" 503 592 "http://localhost/" "Mozilla/5.0 (X11;
Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
all thing it did but still i can't access my server which is working inside the container i am not able figure out issue what i am doing wrong.
YML file througth which i setup nginx-proxy
# A Docker Compose application with mysql and virtual hosting through nginx-proxy for multiple moqui instances on different hosts.
# This has no moqui instances, meant to be a shell for externally managed moqui containers.
# Run with something like:
# $ docker-compose -f nginx-mysql-compose.yml -p moqui up -d
# This sets the project/app name to 'moqui' and the network will be 'moqui_default', to be used by external moqui containers
# To import data using port 3306 mapped for 127.0.0.1 only use something like from the docker host:
# $ mysql -p -u root -h 127.0.0.1 moqui < mysql-export.sql
version: "2"
services:
nginx-proxy:
# For documentation on SSL and other settings see:
# https://github.com/jwilder/nginx-proxy
image: jwilder/nginx-proxy
container_name: nginx-proxy
restart: always
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
# note: .crt, .key, and .dhparam.pem files start with the domain name in VIRTUAL_HOST (ie 'moqui.local.*') or use CERT_NAME env var
- ./certs:/etc/nginx/certs
- ./nginx/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf
environment:
# use SSL_POLICY to disable TLSv1.0, etc in nginx-proxy
- SSL_POLICY=AWS-TLS-1-1-2017-01
moqui-database:
image: mysql:8.0
container_name: moqui-database
restart: always
# expose the port for use outside other containers, needed for external management (like Moqui Instance Management)
ports:
- 127.0.0.1:3308:3306
# edit these as needed to map configuration and data storage
volumes:
- ./db/mysql/data:/var/lib/mysql
# - /my/mysql/conf.d:/etc/mysql/conf.d
environment:
- MYSQL_ROOT_PASSWORD=moquiroot
- MYSQL_DATABASE=moqui
- MYSQL_USER=moqui
- MYSQL_PASSWORD=moquiroot

