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
Related
I am using jwilder nginx proxy container with custom HTTPS port and unable to figure out why the reverse proxy redirects to http instead of https. I have to enter the URL twice with https to load the page or else it keeps on redirecting to http. On the browser development tools, i can see it returns 302 code with location that doesn't contain https.
Not sure how to fix that. Gone through the documentation and it suggested to use HTTPS_METHOD set to nohttp but that didn't fix the issue either.
The docker-compose file looks something like this:
superset:
env_file: docker/.env-non-dev
image: *superset-image
container_name: superset_app
command: ["/app/docker/docker-bootstrap.sh", "app-gunicorn"]
user: "root"
restart: unless-stopped
ports:
- 8088:8088
depends_on: *superset-depends-on
volumes: *superset-volumes
environment:
CERT_NAME: superset.local
VIRTUAL_PORT: 8088
VIRTUAL_HOST: superset.upstream
HTTPS_PORT: 4443
HTTPS_METHOD: nohttp
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- "4443:4443"
volumes:
- .certs:/etc/nginx/certs
- /var/run/docker.sock:/tmp/docker.sock:ro
environment:
DEFAULT_HOST: superset.upstream
HTTPS_PORT: 4443
CERT_NAME: superset.local
HTTPS_METHOD: nohttp
HSTS: 'off'
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
.............
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?
I am trying to setup a LEMP local development environment using Docker. Following is my docker-composer.yml:
version: '2'
services:
apache:
build:
context: ./docker/apache-php7
dockerfile: Dockerfile
image: foo/apache-php7
volumes:
- .:/var/www/html
ports:
- "80:80"
- "443:443"
networks:
- localnet
node:
build:
context: ./docker/node
dockerfile: Dockerfile
image: foo/node
volumes:
- .:/var/www/html
networks:
- localnet
mysql:
image: mysql:5.7
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "root"
MYSQL_USER: "root"
MYSQL_PASSWORD: "root"
volumes:
- mysqldata:/var/lib/mysql
networks:
- localnet
redis:
image: redis:alpine
volumes:
- redisdata:/data
networks:
- localnet
networks:
localnet:
driver: "bridge"
volumes:
mysqldata:
driver: "local"
redisdata:
driver: "local"
I can access the site by going to http://localhost. Instead of accessing the project using http://localhost, I am trying to map it to http://foo.dev but for the life of me I just can't figure out how I can achieve that? One example I have seen is this but it's using a different image and it is also using nginx.
I am assuming that the foo/apache-php7 image is forked from nimmis/apache-php7, which is based on Ubuntu 16.04, so by default your Apache will answer the same way to HTTP requests, irrespective of host name.
So, the only thing you need to do is to set up A/AAAA records in the foo.dev DNS zone pointing at your server.
It looks like the zone needs some attention in any case:
% host foo.dev
foo.dev has address 127.0.53.53
foo.dev mail is handled by 10 your-dns-needs-immediate-attention.dev.
The address record points to a localhost address, which won't work until you're actually on the same host. You'll need a globally routed IP address there.
All I needed to do was simply add the ServerName directive in the apache conf file for the site in question. In my case, it was the 000-default.conf. I didn't even need to update the hosts file as I am marking Gerd's answer as the answer as that is what directed me to this:
ServerName foo.dev
I then updated my hosts file with the following:
127.0.0.1 foo.dev www.foo.dev
I currently am trying to learn how to use docker and was wondering if there is a way to make a Docker stack that includes Wordpress, SQL, and Nginx.
Right now I want to have 3 containers running, 1 for each and use nginx as a reverse proxy for my wordpress app.
However, every time I attempt to get this stack up and running through a composer file, only Wordpress and SQL get linked, but not the Nginx.
version: '2'
services:
db:
image: mysql:5.7
volumes:
- "./.data/db:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:fpm
links:
- db
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
nginx:
restart: always
image: nginx
ports:
- "80:80"
This is all I have in my docker-compose.yml
Your basic approach should work. I have a feeling there is a configuration issue somewhere, possibly with nginx that is preventing it from working as you intend.
You can try this similar docker-compose.yml file as a sample to see how it may differ from what you are doing:
docker-compose.yml
version: '2'
services:
php:
image: phpmyadmin/phpmyadmin
links:
- mysql:db
depends_on:
- mysql
mysql:
image: k0st/alpine-mariadb
volumes:
- ./data/mysql:/var/lib/mysql
environment:
- MYSQL_DATABASE=mydb
- MYSQL_USER=myuser
- MYSQL_PASSWORD=mypass
nginx:
image: nginx:stable-alpine
ports:
- "81:80"
volumes:
- ./nginx/log:/var/log/nginx
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/files:/var/www/nginx:ro
depends_on:
- php
nginx/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile off;
server {
listen 80;
location / {
proxy_pass http://php;
proxy_set_header Host $host;
proxy_redirect off;
}
}
}
The nginx config is simplified but that should work for testing -- basically all it's doing is proxying the php app. Maps to port 81 to avoid conflicts on the host. (Note this is just a rough demo, would need to be fleshed out for any use more than that.)
Regarding linking, you can see that if you run: docker-compose exec mysql ping -c2 nginx to ping from the mysql container to the nginx container, you will succeed even though there are no links specified between these containers. Docker Compose will maintain those links in the default network for you.
If you like, you can fetch a working version from this repo here and run docker-compose up, and (assuming you don't have anything running on port 81) see results on http://localhost:81/ (or whatever your corresponding hostname/IP is).
For more info on Docker Compose networking see:
https://docs.docker.com/compose/networking/
By default Compose sets up a single network for your app. Each
container for a service joins the default network and is both
reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
Links allow you to define extra aliases by which a service is
reachable from another service. They are not required to enable
services to communicate - by default, any service can reach any other
service at that service’s name.
You could go with the jwilder-nginx docker image. It is using docker-gen to detect containers, and will register them in nginx.conf.
This should work, if you add "VIRTUAL_HOST" the domain will be added to nginx.conf. Please note: You don't have to expose ports on WordPress with this Setup. jwilder-nginx will use default port to forward traffic.
version: '2'
services:
db:
image: mysql:5.7
volumes:
- "./.data/db:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:fpm
links:
- db
- nginx
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
VIRTUAL_HOST: myblog.mydomain.de
nginx:
restart: always
image: jwilder/nginx-proxy
ports:
- "80:80"