立ち上げ手順
ソースコード入手
git clone https://github.com/minegishirei/DockerImages.git
ディレクトリ移動
cd DockerImages/nginx
コンテナ立ち上げ
docker-compose up
にアクセス。
以上。終わり。
解説
docker-comopse.ymlファイル
version: "3" services: nginx: container_name: nginx build: ./nginx ports: - "80:80" - "443:443" volumes: - ./nginx/html:/usr/share/nginx/html - ./nginx/conf.d:/etc/nginx/conf.d
ports
について
portは80番と443番を開けている。 これはそれぞれHTTPとHTTPSで使用するポート番号に対応しており、 これがなければブラウザからアクセスすることができない。
volumes
について
nginxで必要なフォルダーは主に二つ。
html
フォルダー。ここにはウェブサイトに表示されるhtmlを格納する。conf.d
フォルダー。ここにはnginxで使用する設定ファイルを格納する。
html
にはindex.html
のみを入れている。
conf.d
にはdefault.conf
ファイルを入れており、この中にnginxの設定内容を書き込んでいる。
nginx/conf.d/default.conf
について
この設定ファイルには次の内容を書き込んでいる。
server { listen 80; server_name localhost; location / { # ゲストOS上のWebアプリ(index.html等)カレントディレクトリ root /usr/share/nginx/html; index index.html index.htm; } }