docker-compose + letsencrypt + nginx-proxy. Where is nginx.conf? - nginx

I'm using this library, and it works as expected. I just want to add an attribute client_max_body_size 50M to Nginx, but where to add it in the docker-compose file:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- '80:80'
- '443:443'
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- nginx-certs:/etc/nginx/certs:ro
- nginx-vhost:/etc/nginx/vhost.d
- nginx-html:/usr/share/nginx/html
labels:
- com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true
restart: always
letsencrypt-nginx-proxy-companion:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-letsencrypt
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- nginx-certs:/etc/nginx/certs
- nginx-vhost:/etc/nginx/vhost.d
- nginx-html:/usr/share/nginx/html
restart: always
depends_on:
- "nginx-proxy"

You need to create a docker file with that configuration and add build config in the docker-compose file.
First, create a Dockerfile named nginx_proxy.df with the following content.
FROM jwilder/nginx-proxy
RUN echo "client_max_body_size 50m;" >> /etc/nginx/conf.d/custom_proxy_settings.conf
Then add it to the same location of docker-composer file.
Update your docker-compose file like this.
nginx-proxy:
build:
context: ./
dockerfile: nginx_proxy.df
container_name: nginx-proxy
.............

Related

Docker Wordpress Setup with Volume for Theme Folder

I created a setup for a wordpress installation with docker-compose:
version: '3'
services:
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
env_file: .env
volumes:
- dbdata-dev:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'
networks:
- rn-dev-network
wordpress:
depends_on:
- db
image: wordpress:5.5.3-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=$MYSQL_DATABASE
volumes:
- ./wordpress/wp-content:/var/www/html/wp-content
- ./wordpress/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
- wordpress-dev:/var/www/html
networks:
- rn-dev-network
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress-dev:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
networks:
- rn-dev-network
volumes:
wordpress-dev:
dbdata-dev:
networks:
rn-dev-network:
driver: bridge
Via FTP, I moved a theme into the wp-content/themes folder. The theme shows up on wordpress when starting the container, but it does not show any preview picture and is missing all pictures/assets when loading it.
I don't see what is missing. When I ssh into the container and check the folder, the volume is correctly linked and the wordpress theme is showing up in the correct folder.
Preview Screen of Wordpress Theme Setup
You need to mount the image file to the nginx container, because static content is served via the nginx container.
The Php container only executes the php.
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress-dev:/var/www/html
- ./wordpress/wp-content:/var/www/html/wp-content
- ./nginx-conf:/etc/nginx/conf.d
networks:
- rn-dev-network

Docker - nginx with custom conf

When running docker-compose up with the following docker-compose.yml file, nginx immediately exits after starting. When I remove the following line:
- ./nginx/config:/etc/nginx/conf.d
nginx does not immediately exit.
docker-compose.yml
version: '3'
services:
nginx:
image: nginx
ports:
- '8080:80'
volumes:
- ./nginx/log:/var/log/nginx
- ./nginx/config:/etc/nginx/conf.d
- ../wordpress:/var/www/wordpress
php:
image: php:fpm
ports:
- 9000:9000
mysql:
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: secret
volumes:
- ./mysql/data:/var/lib/mysql
How can I get nginx to run with a custom /etc/nginx/conf.d/default.conf?

How do I set the configuration of the port 8000 on nginx with docker?

I need to get callback url like http://localhost:8000/auth/facebook/callback.
But the port 8000 is closed in myapp.
How can I set the configuration to open the port 8000 on nginx with docker?
docker version : 17.03.1-ce
docker-compose.yml
version: '3'
services:
web:
build:
context: ./
dockerfile: web.docker
image: my_web
volumes:
- ./www:/var/www
ports:
- "80:80"
networks:
- webnet
app:
build:
context: ./
dockerfile: app.docker
image: my_app
volumes:
- ./www:/var/www
networks:
- webnet
networks:
webnet:

Reverse proxy nginx with Docker

I have a website with a Docker container.
So I use the nginx reverse proxy docker with let's encrypt
I follow this tutorial
But my website is not working with https.
There is my docker compose file:
services:
nginx:
image: pixelfordinner/nginx
container_name: pixelcloud-nginx_proxy-nginx
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- "./volumes/conf.d:/etc/nginx/conf.d:ro"
- "./volumes/vhost.d:/etc/nginx/vhost.d:ro"
- "./volumes/certs:/etc/nginx/certs:ro"
- "/usr/share/nginx/html"
nginx-proxy:
image: jwilder/docker-gen
container_name: nginx-proxy
depends_on:
- nginx
volumes_from:
- nginx
volumes:
- "/var/run/docker.sock:/tmp/docker.sock:ro"
- "./data/templates:/etc/docker-gen/templates:ro"
- "./volumes/conf.d:/etc/nginx/conf.d:rw"
entrypoint: /usr/local/bin/docker-gen -notify-sighup pixelcloud-nginx_proxy-nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
letsencrypt-nginx-proxy:
restart: always
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: ssl
depends_on:
- nginx
- nginx-proxy
volumes_from:
- nginx
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./volumes/vhost.d:/etc/nginx/vhost.d:rw"
- "./volumes/certs:/etc/nginx/certs:rw"
environment:
- "NGINX_DOCKER_GEN_CONTAINER=pixelcloud-nginx_proxy-docker_gen"
wordpress:
image: wordpress
environment:
- VIRTUAL_HOST=foo.example.com
- LETSENCRYPT_HOST=foo.example.com
- LETSENCRYPT_EMAIL= mail#example.com
I download the nginx.tmpl file from github, and copy it into /data/templates/nginx.tmpl
I don't inderstand what it is not working
Thanks for help!
UPDATE: I managed to setup https instead of http on wordpress.
But I have a Gitlab instance with docker compose. On the login page, the https is working, but when I login and go on the project homepage, there is https but the connection is not secure.
I would like this: https://gitlab.exemple.com
It looks like you are missing the jwilder/docker-gen container that is required by jrcs/letsencrypt-nginx-proxy-companion.
See documentation: https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion#separate-containers-recommended-method
See example: https://github.com/fatk/docker-letsencrypt-nginx-proxy-companion-examples/blob/master/docker-compose/v2/simple-site/docker-compose.yml
It means you will have to add a nginx.tmpl file and mount it to your jwilder/docker-gen container.
You will also need to share the /etc/nginx/vhost.d volume from the nginx-proxy container.
Update:
The container_name of your service running the docker-gen image should be pixelcloud-nginx_proxy-docker_gen as it needs to match the NGINX_DOCKER_GEN_CONTAINER environment variable. So you should have:
nginx-proxy:
image: jwilder/docker-gen
container_name: pixelcloud-nginx_proxy-docker_gen

Curl do Docker Container on same Docker Host (nginx-proxy)

I have a setup based on docker-letsencrypt-nginx-proxy-companion running a django container and a wordpress container on the same Docker Host. I have added to domains to each of the container, so the wordpress container is reachable with mydomain.com and www.mydomain.com and the django container with subdomain.mydomain.com. This is configured in the VIRTUAL_HOST env and its working perfectly so far. I get all certificates and I can connect to each of them.
The main Issue I have now is, that the wordpress container needs to curl the django container and vice versa. But if I go into the django or wordpress container and try to make a call to e.g. subdomain.mydomain.com I get the following error:
$ curl mydomain.com
Hostname was NOT found in DNS cache
and then he tries to connect to the IP and is ending up in a timeout. If I make a curl from local or a different server I get a 200 without any problems on each of those. I read sth about a DNS resolve issue but atm I couldn't find a solution. Do you have a clue what I could do in this case?
Thanks in advance!
My Containers:
Nginx Proxy Compose
version: "2"
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- "/var/www/certificates:/etc/nginx/certs:ro"
- "/etc/nginx/vhost.d"
- "/usr/share/nginx/html"
- "/var/run/docker.sock:/tmp/docker.sock:ro"
letsencrypt-nginx-proxy-companion:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt-nginx-proxy-companion
restart: always
volumes_from:
- nginx-proxy
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "/var/www/certificates:/etc/nginx/certs:rw"
networks:
default:
external:
name: proxy-network
Wordpress Compose
version: '2'
services:
mariadb:
build:
context: .
dockerfile: build/env/mysql/Dockerfile
env_file: .env
restart: "always"
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- prod-database:/var/lib/mysql
php:
build:
context: .
dockerfile: build/env/php-fpm/Dockerfile
env_file: .env
restart: "always"
volumes:
- ${SRC_APP_PERSISTENT}:/var/www/html
links:
- mariadb:mysql
web:
build:
context: .
dockerfile: build/env/nginx/Dockerfile
restart: "always"
links:
- php:fpm
volumes_from:
- php
environment:
- VIRTUAL_HOST=mydomain.com,www.mydomain.com
- VIRTUAL_PORT=443
- VIRTUAL_NETWORK=proxy-network
- LETSENCRYPT_HOST=mydomain.com,www.mydomain.com
- LETSENCRYPT_EMAIL=info#mydomain.com
ports:
- "80"
volumes:
prod-database:
driver: local
networks:
default:
external:
name: proxy-network
Django Compose
version: '2'
volumes:
postgres_data_dev: {}
postgres_backup_dev: {}
services:
postgres:
build: ./compose/postgres
volumes:
- postgres_data_dev:/var/lib/postgresql/data
- postgres_backup_dev:/backups
environment:
- POSTGRES_USER=dbuser
django:
build:
context: .
dockerfile: ./compose/django/Dockerfile-dev
env_file: .env
command: /start-dev.sh
depends_on:
- postgres
environment:
- POSTGRES_USER=dbuser
- USE_DOCKER=yes
- VIRTUAL_HOST=subdomain.mydomain.com
- VIRTUAL_PORT=443
- VIRTUAL_NETWORK=proxy-network
- LETSENCRYPT_HOST=subdomain.mydomain.com
- LETSENCRYPT_EMAIL=info#mydomain.com
volumes:
- .:/app
ports:
- "8000"
links:
- postgres
- mailhog
pycharm:
build:
context: .
dockerfile: ./compose/django/Dockerfile-dev
depends_on:
- postgres
environment:
- POSTGRES_USER=dbuser
volumes:
- .:/app
links:
- postgres
mailhog:
image: mailhog/mailhog
ports:
- "8025:8025"
networks:
default:
external:
name: proxy-network

Resources