大网数据广告活动
服务器运维问答

nginx can't find /etc/letsencrypt/options-ssl-ngin.conf file

· 52CE 我爱测

I'm trying to serve a python-django webapp using a linux box (running ubuntu 18.04) with nginx, gunincorn, letsencrypt and docker. After following a number of online tutorials I have been successful in serving the app via http th…

问题原文

原帖链接 · Matt Ellis · CC BY-SA 4.0

I'm trying to serve a python-django webapp using a linux box (running ubuntu 18.04) with nginx, gunincorn, letsencrypt and docker. After following a number of online tutorials I have been successful in serving the app via http through port 80 by following this tutorial http://pawamoy.github.io/2018/02/01/docker-compose-django-postgres-nginx.html.

However, I am now really struggling with deploying via https through port 443. I think maybe I am not understanding a fundamental docker concept. The error I get when running sudo docker-compose up is below.

NGINX ERROR:

nginx_1 | nginx: [emerg] open() "/etc/letsencrypt/options-ssl-nginx.conf" failed (2: No such file or directory) in /etc/nginx/conf.d/local_ssl.conf:28

I believe this is because I have not linked the options-ssl-nginx.conf file in the docker-compose.yml file, maybe through a volume? I do not know if this is right though. The relevant parts of my docker-compose.yml file and nginx.conf files are below:

docker-compose.yml:

version: '3'

services:

  # database containers
  database1:
    ...

  # web container
  djangoapp:
    ...

  # reverse proxy container (nginx)
  nginx:
    image: nginx:latest
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./config/nginx/conf_ssl.d/:/etc/nginx/conf.d
      - static:/opt/services/djangoapp/static
      - media:/opt/services/djangoapp/media
      - ~/nginxlogs:/var/log/nginx
      - /etc/letsencrypt
      - /var/www/certbot
/live/maps.critr.org.uk
    networks:
      - nginx_network
    depends_on:
      - djangoapp

  certbot:
    image: certbot/certbot
    restart: unless-stopped
    volumes:
      - /etc/letsencrypt
      - /var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"

networks:
   ...

volumes:
   ...

nginx.conf:

upstream critr_server {
    server djangoapp:8000;
}

# divert all http traffic to https
server {
    listen 80; 
    server_name maps.critr.org.uk;
    return 301 https://maps.critr.org.uk;
}

server {

    listen 443 ssl;

    server_name maps.critr.org.uk;

    ssl_certificate /etc/letsencrypt/live/maps.critr.org.uk/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/maps.critr.org.uk/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers   HIGH:!aNULL:!MD5;


    include         /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam     /etc/letsencrypt/ssl-dhparams.pem;


    location /.well-known {
        root /opt/services/djangoapp/static/;
    }   

    location /static/ {
        alias /opt/services/djangoapp/static/;
    }   

    location /media/ {
        alias /opt/services/djangoapp/media/;
    }   

    location / { 
        proxy_pass https://critr_server;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }   
}

I believe this is a problem with not understanding volumes in docker-compose? Though I've been trying to solve this for almost a week now and come up with nothing.

社区高分解答

原帖链接 · Unicornist · CC BY-SA 4.0

It seems you are missing /etc/letsencrypt/options-ssl-nginx.conf this file is the default configuration for all sites using a certbot installer. So this file normally gets created during the certificate installation (or issuing and installation) which mainly happens manually by someone whois configuring the system for the first time.

So you can either:

  1. Get the latest version of this file from its GitHub location at https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf and put it back where it should be
  2. OR change your nginx.conf file and replace the line that gives the error (the line that includes that file) with the content of it you get from Github.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-01-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。