我是 docker 新手,尝试基于 Alpine 构建一个镜像来管理我的带有 HTTPS 连接的网站。目前我正处于使其从容器中运行的步骤,因此我的 Dockerfile 尚未完成:
FROM alpine
RUN apk update \
&& apk upgrade \
&& apk add nginx php7 php7-fpm php7-opcache php7-gd php7-mysqli php7-zlib php7-curl \
&& mkdir /run/nginx
EXPOSE 80
从那里我开始我的容器:
docker run -ti -p 80:80 -p 443:442 -v /home/docker/web/conf:/etc/nginx/conf.d/ -v /home/docker/web/www:/var/www/localhost/htdocs test
然后我安装 certbot-nginx,并启动它来生成我的证书,我将其复制到我的 /var/www/localhost/htdocs/example.fr/ 中以便从容器外部访问它。最后我启动 php-fpm7 和 nginx。
我的 nginx 配置:
server {
server_name example.fr;
root /var/www/localhost/htdocs/example.fr;
index index.html index.htm index.php;
listen [::]:443 ssl;
server_tokens off;
# configure php
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
index index.html index.htm index.php;
}
location ~* \.pem {
deny all;
}
ssl_certificate /var/www/localhost/htdocs/example.fr/fullchain.pem;
ssl_certificate_key /var/www/localhost/htdocs/example.fr/privkey.pem; # managed by Certbot
}
server {
if ($host = example.fr) {
return 301 https://$host$request_uri;
}
# managed by Certbot
server_name example.fr;
listen 80;
listen [::]:80;
#return 404;
}
我可能遗漏了一些简单的东西但是我已经困惑一个星期了。谢谢!