• 欢迎订阅我的Youtube频道
  • 欢迎加入我的电报群

Add HTTPS to wordpress running in docker container

网站建设 fennng 1年前 (2018-04-25) 756次浏览 0个评论
I have a wordpress website running in a docker instance in azure. It’s running over HTTP and I would like to add HTTPS for it.
This can be done easier by a few commands.
// Run companion which used to generate SSL certificate from letsencrypt.org, replace /home/fennng/certs to your own chosen path on your linux host.
sudo docker run \
–name companion \
-v /home/fennng/certs:/etc/nginx/certs:rw \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
–volumes-from nginx-proxy \
jrcs/letsencrypt-nginx-proxy-companion
​//Run a new wordpress container instance. Because my wordpress files are hosted on azure file and can be mounted as a volume, I can run wordpress instance as many as I want. They will use same wordpress file and connect to the same db.
sudo docker volume create -d azurefile –name vol3 -o share=wpacishare
docker stop wp2 && docker rm wp2 && \
  sudo docker run -d –name wp2 \
    -e VIRTUAL_HOST=http://www.dengnz.com \
    -e “LETSENCRYPT_HOST=http://www.dengnz.com” \
    -e “LETSENCRYPT_EMAIL=youremail_address” \
     -v vol3:/var/www/html -p 8082:80 wordpress 
​Stop the original wordpress instance and run nginx-proxy. Do not delete the old wordpress container, in case there is an incident,  we can start it again. Your nginx server has to listen to port 80 for letsencrypt to verify the domain. The port 80 must be public.
docker stop wp && \
sudo docker run -p 80:80 -p 443:443 \
  –name nginx-proxy \
  -v /home/fennng/certs:/etc/nginx/certs:ro \
  -v /etc/nginx/vhost.d \
  -v /usr/share/nginx/html \
  -v /var/run/docker.sock:/tmp/docker.sock:ro \
  –label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy \
  jwilder/nginx-proxy
​Now just wait a moment,
Your certificate will be generated in a few seconds

​You will see something like this in your nginx log, which is a request from letsencrypt to verify your domain.

http://www.dengnz.com 66.133.109.36 – – [26/Apr/2018:10:53:10 +0000] “GET /.well-known/acme-challenge/uFc

​ds​

QYMADRKPwxgg_CeLKMRfdAaNpT23hsY4OH3NikFo HTTP/1.1″ 200 87 “-” “Mozilla/5.0 (compatible; Let’s Encrypt validation server; +https://www.letsencrypt.org)”

​Your HTTPS should be working now. Don’t forget to have both of your 80 and 443 exposed to public.​
Although the certificate generated by let’s Encrypt only valid for 3 months, you don’t have to worry about it because the certificate will be renewed automatically.

峰享技术 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Add HTTPS to wordpress running in docker container
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址