Wordpress inside docker container behind nginx proxy with ssl
Finally, I found the solution. The reverse proxy was working well.The problem was in the wordpress configuration which is waiting for $_SERVER['HTTPS'] = 'on'
. But as I am working on nginx inside my container, wordpress keep redirecting the website on HTTPS.
So I just set $_SERVER['HTTPS'] = 'on';
at the top of wp-config.php and that's it.
Hope this can help sometime.
You are getting too many redirects because you're listening on 443:
listen *:443 ssl;
And redirecting to 443
proxy_set_header X-Forwarded-Proto https;
Remove this line from your nginx.conf:
proxy_set_header X-Forwarded-Proto https;
Just had a similar problem setting everything up. Below is an example YAML file that worked for me.
version: '2'services: wordpress: image: wordpress ports: - 8080:80 environment: WORDPRESS_DB_PASSWORD: MyPassword VIRTUAL_HOST: example.com # replace with real domain LETSENCRYPT_HOST: example.com # replace with real domain LETSENCRYPT_EMAIL: email@email.com # replace with real email mysql: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: MyPassword nginx-proxy: image: jwilder/nginx-proxy container_name: nginx-proxy ports: - 80:80 - 443:443 volumes: - /etc/certs:/etc/nginx/certs:ro - /var/run/docker.sock:/tmp/docker.sock:ro - /etc/nginx/vhost.d - /usr/share/nginx/html labels: com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true" letsencrypt: image: jrcs/letsencrypt-nginx-proxy-companion container_name: letsencrypt volumes: - /etc/certs:/etc/nginx/certs:rw - /var/run/docker.sock:/var/run/docker.sock:ro volumes_from: - nginx-proxy