15
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Docker+nginxでHTTPSサーバを簡単に構築

Posted at

DockerのVolumeをホスト側に持って証明書と設定ファイルとHTMLを置いて読ませる。
他の環境とセットで動かしたかったのでDocker-composeにしているが、もちろんDocker単体でも良い。

Let's encryptで証明書を取得し以下に格納しておく。
手順は他に参考記事がたくさんあるのでここでは触れず。
ホスト側の置き場所はDockerからアクセスできる場所ならどこでも良い。

./nginx/conf/certs

default.confを作成し./conf.dに置く。
HTTP 80番は使わないので書かず。

server {
    listen              443                 ssl;
    server_name      your.hostname; # 自分で取得したホスト名に変更
    ssl_certificate     /etc/nginx/certs/server.crt;
    ssl_certificate_key /etc/nginx/certs/server.key;

    location / {
        root   /usr/share/nginx/html;
    }
}

これで完了。スタートさせる。

(必要なら)
htmlを用意してホストに置いておく
./html

docker-composeをこのようにかく。

docker-compose.yml
nginx:
  restart: always
  image: nginx
  volumes:
          - ./html:/usr/share/nginx/html:ro
          - ./conf.d:/etc/nginx/conf.d
          - ./nginx/conf/certs:/etc/nginx/certs
  ports:
    - "8080:443" # デフォルト443のままで良いなら不要
15
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?