понедельник, 31 декабря 2018 г.

Настройка обратного прокси nginx docker-compose на примере wordpress

Setting up a Reverse-Proxy with Nginx and docker-compose
Use NGINX As A Reverse Proxy To Your Containerized Docker Applications
Docker compose : NGINX reverse proxy with multiple containers
Nextcloud via Docker with nginx reverse proxy
Docker Compose wordpress

$ sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

$ mkdir  -p /home/user/wordpress
$ nano /home/user/wordpress/docker-compose.yml

version: '3'

services:
   db:
     image: mysql:5.7
     container_name: db
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     container_name: wordpress
     expose:
       - "80"
     volumes:
       - html:/var/www/html
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress

   nginx:
    image: nginx:latest
    container_name: production_nginx
    volumes:
     - ./nginx.conf:/etc/nginx/nginx.conf
     - ./certs:/etc/letsencrypt
    restart: always
    ports:
      - 80:80
      - 443:443

volumes:
    db_data:
    html:

Сохранить

$ nano /home/user/production_nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections  1024;
}

http {
  upstream target {
      server wordpress:80;
  }

  server {
      listen 443 ssl;
      server_name zaz60.com;
      ssl_certificate /etc/letsencrypt/live/zaz60.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/zaz60.com/privkey.pem;

      location / {
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header X-Forwarded-Port $server_port;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_pass http://target;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "Upgrade";
          # This allows the ability for the execute shell window to remain open for up to 15 minutes. Without this parameter, the default is 1 minute and will automatically close.
          proxy_read_timeout 900s;
      }
  }

  server {
      listen 80;
      server_name zaz60.com;
      return 301 https://$server_name$request_uri;
  }
}

Сохранить

$ cd /home/user/wordpress

$ docker-compose up -d
$ docker-compose down


Комментариев нет:

Отправить комментарий