繁体   English   中英

SSL 在 Nginx docker 容器中不工作

[英]SSL not working in Nginx docker container

我有一个这样的项目结构:

├── docker-compose.dev.yml
├── docker-compose.prod.yml
├── docker-compose.yml
├── homeid
│             ├── Dockerfile
│             ├── nginx.conf
│             └── website
├── reverse-proxy
│             ├── Dockerfile
│             ├── dev.homebooker.conf
│             ├── homebooker.conf
│             └── nginx.conf

and I have a domain homebooker.fr and a subdomain dev.homebooker.fr , and I want to add https , so I got a certificate from letsencrypt and I mouted it into Nginx container, but https is not working, do not know what I我做错了。

以下是文件的内容:

docker-compose.yml

version: '3'

services:
  reverse_proxy:
    build:
      context: ./reverse-proxy
      dockerfile: Dockerfile
    container_name: reverse_proxy
    restart: always
    volumes:
      - ~/letsencrypt:/etc/letsencrypt
    networks:
      - dev_network
      - prod_network
    ports:
      - "80:80"
      - "433:433"

networks:
  dev_network:
  prod_network:

docker-compose.dev.yml

version: '3'

services:
  homeid_dev:
    build:
      context: ./homeid
      dockerfile: Dockerfile
    container_name: homeid_dev
    restart: always
    networks:
      - dev_network
    ports:
      - '8001:80'

networks:
  dev_network:

docker-compose.prod.yml

version: '3'

services:
  homeid_prod:
    build:
      context: ./homeid
      dockerfile: Dockerfile
    container_name: homeid_prod
    restart: always
    networks:
      - prod_network
    ports:
      - "8002:80"
networks:
  prod_network:

家庭编号 Dockerfile:

FROM nginx:1.21.6-alpine

RUN apk --update --no-cache upgrade
RUN apk add python3 python3-dev py3-pip build-base libressl-dev musl-dev libffi-dev rust cargo
RUN pip3 install pip --upgrade
RUN pip3 install certbot-nginx
RUN mkdir /etc/letsencrypt

WORKDIR /usr/share/nginx/html

COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY ./website package.json package-lock.json ./

RUN npm install

反向代理 Dockerfile:

FROM nginx:1.21.6-alpine

RUN apk --update --no-cache upgrade
RUN apk add python3 python3-dev py3-pip build-base libressl-dev musl-dev libffi-dev rust cargo
RUN pip3 install pip --upgrade
RUN pip3 install certbot-nginx
RUN mkdir /etc/letsencrypt

COPY nginx.conf /etc/nginx/nginx.conf

WORKDIR /etc/nginx/sites-available
COPY homebooker.conf /etc/nginx/sites-available/homebooker.fr.conf

WORKDIR /etc/nginx/sites-available
COPY dev.homebooker.conf /etc/nginx/sites-available/dev.homebooker.fr.conf

WORKDIR /etc/nginx/sites-enabled
RUN ln -s /etc/nginx/sites-available/homebooker.fr.conf . \
    && ln -s /etc/nginx/sites-available/dev.homebooker.fr.conf .

dev.homebooker.fr.conf

server {
    listen       80;
    listen  [::]:80;
    server_name dev.homebooker.fr www.dev.homebooker.fr;

    location = /status {
        access_log off;
        default_type text/plain;
        add_header Content-Type text/plain;
        return 200 "alive";
    }

    location / {
        proxy_pass http://homeid_dev;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

homebooker.fr.conf

server {
    listen 80 ;
    listen [::]:80 ;
    server_name homebooker.fr www.homebooker.fr;
    return 301 https://homebooker.fr;
}

server {
    listen 443 ssl;

    server_name homebooker.fr www.homebooker.fr;

    # RSA certificate
    ssl_certificate /etc/letsencrypt/live/homebooker.fr/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/homebooker.fr/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;

    location = /status {
        access_log off;
        default_type text/plain;
        add_header Content-Type text/plain;
        return 200 "alive";
    }

    location / {
        proxy_pass http://homeid_prod/;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

反向代理/nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include /etc/nginx/sites-enabled/*;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

homeid/nginx.conf

server {
    listen       80;
    listen  [::]:80;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

问题是 https 的端口错误,我应该在 docker-compose.yml 中公开端口号 443 而不是 433

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM