启用ssl到docker nginx容器

时间:2018-03-23 14:17:55

标签: php docker ssl nginx docker-compose

我正在尝试在我的本地nginx docker容器上启用SSL。 我尝试更改我的Dockerfile:

# install openssl
RUN apk add --no-cache openssl

# create a folder for the keys
RUN mkdir /etc/nginx/ssl 2> /dev/null

# generate the keys for your local domain
RUN openssl genrsa -out "/etc/nginx/ssl/YOURLOCALDOMAIN.key" 2048 \
&& openssl req -new -key "/etc/nginx/ssl/YOURLOCALDOMAIN.key" -out "/etc/nginx/ssl/YOURLOCALDOMAIN.csr" -subj "/CN=YOURLOCALDOMAIN/O=YOURCOMPANYNAME/C=UK" \
&& openssl x509 -req -days 365 -in "/etc/nginx/ssl/YOURLOCALDOMAIN.csr" -signkey "/etc/nginx/ssl/YOURLOCALDOMAIN.key" -out "/etc/nginx/ssl/YOURLOCALDOMAIN.crt"

我的网站配置文件:

server {
listen 80;
listen 443 ssl;
listen [::]:80;
server_name {SITE_NAME};
root /var/www/{DOCUMENT_ROOT}/public;
index index.php index.html index.htm;

ssl_certificate     {CERTIFICATE_LOCATION};
ssl_certificate_key {KEY_LOCATION};

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~ \.php$ {
    try_files $uri /index.php =404;
    fastcgi_pass php-upstream;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ /\.ht {
    deny all;
}
}

我试图运行后

  

docker-compose build --force-rm --no-cache nginx

但是在我的日志文件中我有这个错误:

  

BIO_new_file(“/ etc / nginx / ssl / mysite.local.crt”)失败(SSL:错误:02001002:系统库:fopen:没有这样的文件或目录:fopen('/ etc / nginx / ssl / mysite .local.crt','r')错误:2006D080:BIO例程:BIO_new_file:没有这样的文件)

你知道怎么解决吗?

由于

0 个答案:

没有答案