вторник, 1 января 2019 г.

Настройка nginx в Docker-compose

Docker-compose: идеальное рабочее окружение

$ 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/production_nginx
$ nano /home/user/production_nginx/docker-compose.yml

version: '3'

services:
   nginx:
    image: nginx:latest
    container_name: production_nginx
    volumes:
     - ./src:/usr/share/nginx/html
     - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    restart: always
    ports:
      - 80:80
      - 443:443

Сохранить.


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

worker_processes 1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        root   /usr/share/nginx/html;
        listen       80;
        server_name  zaz60.com;

        location / {
            index  index.html index.htm;
        }
    }
}

Сохранить.

$ mkdir src
$ nano src/index.html

Hi, I'am Nginx

Сохранить.

$ docker-compose up -d

$ docker-compose down

Вариант с SSL сертифиикатами

$ sudo chown -R user:user certs



$ nano /home/user/production_nginx/docker-compose.yml

version: '3'

services:
   nginx:
    image: nginx:latest
    container_name: production_nginx
    volumes:
     - ./src:/usr/share/nginx/html
     - ./nginx/nginx.conf:/etc/nginx/nginx.conf
     - ./certs:/etc/letsencrypt
    restart: always
    ports:
      - 80:80
      - 443:443

Сохранить.


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

worker_processes 1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        root   /usr/share/nginx/html;
        listen       80;
        listen 443 ssl;
        ssl_certificate /etc/letsencrypt/live/zaz60.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/zaz60.com/privkey.pem;
        server_name  zaz60.com;

        location / {
            index  index.html index.htm;
        }
    }
}

Сохранить.

$ mkdir src
$ nano src/index.html

Hi, I'am Nginx

Сохранить.

$ docker-compose up -d

$ docker-compose down




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

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