问题原文
原帖链接 · MB4E · CC BY-SA 4.0
I'm using something like this docker-compose.yml file.
version: '3'
services:
httpd:
image: httpd:alpine
environment:
- VIRTUAL_HOST=example.com,www.example.com
- LETSENCRYPT_HOST=example.com,www.example.com
- LETSENCRYPT_EMAIL=[email omitted]
ports:
- '1080:80'
proxy:
container_name: my_proxy
image: jwilder/nginx-proxy:alpine
ports:
- '80:80'
- '443:443'
volumes:
- '/var/run/docker.sock:/tmp/docker.sock:ro'
- './volumes/proxy/letsencrypt:/etc/nginx/certs:ro'
- './volumes/proxy/vhost:/etc/nginx/vhost.d'
- './volumes/proxy/html:/usr/share/nginx/html'
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
environment:
- NGINX_PROXY_CONTAINER=my_proxy
- DEFAULT_EMAIL=[email omitted]
volumes:
- '/var/run/docker.sock:/var/run/docker.sock:ro'
- './volumes/proxy/letsencrypt:/etc/nginx/certs'
- './volumes/proxy/vhost:/etc/nginx/vhost.d'
- './volumes/proxy/html:/usr/share/nginx/html'
I have following 301 redirections (and two certificates, one for example.com and one for www.example.com).
This is ok, but I have I'm trying to get following 301 redirections (with only one certificate for the domain www.example.com).
- http://example.com -> https://www.example.com
- https://example.com -> https://www.example.com
- http://www.example.com -> https://www.example.com
Is it possible to do that using this docker images ?
已采纳解答
原帖链接 · MB4E · CC BY-SA 4.0
Here is a working solution, with the following new docker-compose.yml file.
version: '3'
services:
httpd:
image: httpd:alpine
environment:
- VIRTUAL_HOST=www.example.com
- LETSENCRYPT_HOST=example.com,www.example.com
- LETSENCRYPT_EMAIL=[email omitted]
ports:
- '1080:80'
proxy:
container_name: my_proxy
image: jwilder/nginx-proxy:alpine
ports:
- '80:80'
- '443:443'
volumes:
- '/var/run/docker.sock:/tmp/docker.sock:ro'
- './volumes/config/proxy/nginx.conf:/etc/nginx/conf.d/example.conf:ro'
- './volumes/proxy/letsencrypt:/etc/nginx/certs:ro'
- './volumes/proxy/vhost:/etc/nginx/vhost.d'
- './volumes/proxy/html:/usr/share/nginx/html'
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
environment:
- NGINX_PROXY_CONTAINER=my_proxy
- DEFAULT_EMAIL=[email omitted]
volumes:
- '/var/run/docker.sock:/var/run/docker.sock:ro'
- './volumes/proxy/letsencrypt:/etc/nginx/certs'
- './volumes/proxy/vhost:/etc/nginx/vhost.d'
- './volumes/proxy/html:/usr/share/nginx/html'
And here is the content of ./volumes/config/proxy/nginx.conf file.
server {
server_name example.com;
listen 80 ;
listen [::]:80 ;
listen 443 ssl http2;
listen [::]:443 ssl http2;
return 301 https://www.$host$request_uri;
ssl_certificate /etc/nginx/certs/default.crt;
ssl_certificate_key /etc/nginx/certs/default.key;
}
I don't know if it's possible to redirect https://example -> https://www.example.com without using this default ssl certificates.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
