29
26

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 5 years have passed since last update.

docker-compose+nginxでリバースプロキシを設定する

Posted at

#この記事について
dockerで複数Webサービスをたてる時に
他コンテナのサービスをnginxでリバースプロキシをしたので、
その時の設定をまとめます。

構成

サービス

  • nginx
  • jenkins (CIツール)
  • portainer (Dockerコンテナ管理ツール)

遷移したいURL

docker-compose.yml
version: "3"
services:
  nginx:
    build: nginx #./nginx/Dockerfileを使って起動する
    ports:
      - "80:80"
    depends_on: #jenkins,portainerの後に起動させるため設定する
      - jenkins 
      - portainer
  jenkins:
    image: jenkins/jenkins:lts
    environment:
      - JENKINS_OPTS=--prefix=/jenkins #Nginxで設定するためにprefixを指定する
    ports:
      - "8080:8080"
    volumes:
      - ./jenkins/home:/var/jenkins_home
    restart: always
  portainer:
    image: portainer/portainer
    ports:
      - "9001:9000" #右側で指定したポート番号をnginxで使用する
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./portainer/data:/data
    restart: always
./nginx/Dockerfile
FROM nginx # 公式のimageを使う
COPY ./default.conf /etc/nginx/conf.d/default.conf # nginx設定ファイルをコンテナにコピーする

portinerの設定に関しては
https://github.com/portainer/portainer-compose/blob/master/nginx/config/portainer.conf
を参照する

./nginx/default.conf
  upstream portainer {
      server portainer:9000;
  }

  server{
    listen       80;
    server_name  localhost;

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

    location /jenkins {
      proxy_pass    http://jenkins:8080;
    }

    location /portainer/ {
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      proxy_pass    http://portainer/;
    }

    location /portainer/api/websocket/ {
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_http_version 1.1;
      proxy_pass http://portainer/api/websocket/;
   }
}

29
26
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
29
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?