Tiwhikete SSL mo Docker paetukutuku-taupānga

I roto i tenei tuhinga, e hiahia ana ahau ki te whakapuaki ki a koe he tikanga mo te hanga tiwhikete SSL mo to tono paetukutuku e rere ana i runga i te Docker, na te mea... Kaore i kitea e au he otinga penei i te wahanga reo Ruhia o te Ipurangi.

Tiwhikete SSL mo Docker paetukutuku-taupānga

Ētahi atu kōrero i raro i te tapahi.

I a matou he docker v.17.05, docker-compose v.1.21, Ubuntu Server 18 me te pene o Let'sEncrypt parakore. Ehara i te mea he mea tika ki te tuku i nga mahi ki Docker. Engari ka timata koe ki te hanga Docker, ka uaua ki te whakamutu.

Na, ki te timata, ka hoatu e ahau nga tautuhinga paerewa - i a maatau i te waahanga dev, i.e. kaore he tauranga 443 me te SSL i te nuinga:

docker-compose.yml

version: '2'
services:
    php:
        build: ./php-fpm
        volumes:
            - ./StomUp:/var/www/StomUp
            - ./php-fpm/php.ini:/usr/local/etc/php/php.ini
        depends_on:
            - mysql
        container_name: "StomPHP"
    web:
        image: nginx:latest
        ports:
            - "80:80"
            - "443:443"
        volumes:
            - ./StomUp:/var/www/StomUp
            - ./nginx/main.conf:/etc/nginx/conf.d/default.conf
        depends_on:
            - php
    mysql:
        image: mysql:5.7
        command: mysqld --sql_mode=""
        environment:
            MYSQL_ROOT_PASSWORD: xxx
        ports:
            - "3333:3306"

nginx/main.conf

 server {
    listen 80;
    server_name *.stomup.ru stomup.ru;
   root /var/www/StomUp/public;
     client_max_body_size 5M;

    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
  }

    location ~ ^/index.php(/|$) {
      #fastcgi_pass unix:/var/run/php7.2-fpm.sock;
       fastcgi_pass php:9000;
       fastcgi_split_path_info ^(.+.php)(/.*)$;
      include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
       fastcgi_param DOCUMENT_ROOT $realpath_root;
        fastcgi_buffer_size 128k;
       fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
       internal;
    }

    location ~ .php$ {
        return 404;
    }

     error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

I muri mai, me tino whakatinanahia te SSL. Ki te pono, i pau ahau mo te 2 haora ki te ako i te rohe com. He mea whakamere nga whiringa katoa e tukuna ana ki reira. Engari i te wahanga o te kaupapa o naianei, me tere me te pono o taatau (te pakihi). SSL Let'sEnctypt к nginx ipu me te kore ke atu.

Tuatahi, i whakauruhia e matou ki runga i te tūmau certbot
sudo apt-get install certbot

I muri mai, i hangaia e matou he tiwhikete mohoao mo to matou rohe

sudo certbot certonly -d stomup.ru -d *.stomup.ru --manual --preferred-challenges dns


i muri i te mahi, ka whakawhiwhia mai e certbot nga rekoata 2 TXT e tika ana kia tohua ki nga tautuhinga DNS.

_acme-challenge.stomup.ru TXT {тотКлючКоторыйВамВыдалCertBot}


Na ka pehi i te tomo.

I muri i tenei, ka tirohia e certbot te noho o enei rekoata i roto i te DNS me te hanga tiwhikete mo koe.
mena kua tapirihia he tiwhikete engari certbot kaore i kitea - ngana ki te whakaara ano i te whakahau i muri i te 5-10 meneti.

Ana, ko matou nga rangatira rangatira o te tiwhikete Let'sEncrypt mo nga ra 90, engari inaianei me tuku atu ki Docker.

Ki te mahi i tenei, i roto i te huarahi tino iti, i roto i te docker-compose.yml, i te waahanga nginx, ka hono tatou i nga raarangi.

Tauira docker-compose.yml me SSL

version: '2'
services:
    php:
        build: ./php-fpm
        volumes:
            - ./StomUp:/var/www/StomUp
            - /etc/letsencrypt/live/stomup.ru/:/etc/letsencrypt/live/stomup.ru/
            - ./php-fpm/php.ini:/usr/local/etc/php/php.ini
        depends_on:
            - mysql
        container_name: "StomPHP"
    web:
        image: nginx:latest
        ports:
            - "80:80"
            - "443:443"
        volumes:
            - ./StomUp:/var/www/StomUp
            - /etc/letsencrypt/:/etc/letsencrypt/
            - ./nginx/main.conf:/etc/nginx/conf.d/default.conf
        depends_on:
            - php
    mysql:
        image: mysql:5.7
        command: mysqld --sql_mode=""
        environment:
            MYSQL_ROOT_PASSWORD: xxx
        ports:
            - "3333:3306"

Kua hono? Pai - kia haere tonu:

Inaianei me huri tatou i te whirihora nginx ki te mahi tahi 443 tauranga me SSL whānui:

Tauira main.conf whirihora me SSL

#
server {
	listen 443 ssl http2;
	listen [::]:443 ssl http2;

	server_name *.stomup.ru stomup.ru;
	set $base /var/www/StomUp;
	root $base/public;

	# SSL
	ssl_certificate /etc/letsencrypt/live/stomup.ru/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/stomup.ru/privkey.pem;
	ssl_trusted_certificate /etc/letsencrypt/live/stomup.ru/chain.pem;

      client_max_body_size 5M;

      location / {
          # try to serve file directly, fallback to index.php
          try_files $uri /index.php$is_args$args;
      }

      location ~ ^/index.php(/|$) {
          #fastcgi_pass unix:/var/run/php7.2-fpm.sock;
          fastcgi_pass php:9000;
          fastcgi_split_path_info ^(.+.php)(/.*)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
          fastcgi_param DOCUMENT_ROOT $realpath_root;
          fastcgi_buffer_size 128k;
          fastcgi_buffers 4 256k;
          fastcgi_busy_buffers_size 256k;
          internal;
      }

      location ~ .php$ {
          return 404;
      }

      error_log /var/log/nginx/project_error.log;
      access_log /var/log/nginx/project_access.log;
}


# HTTP redirect
server {
	listen 80;
	listen [::]:80;

	server_name *.stomup.ru stomup.ru;

	location / {
		return 301 https://stomup.ru$request_uri;
	}
}

Inaa, i muri i enei mahinga, ka haere matou ki te raarangi me Docker-compose, tuhia docker-compose up -d. Na ka tirohia e matou te mahi a SSL. Me tango nga mea katoa.

Ko te mea nui kia kaua e wareware kua tukuna te tiwhikete Let'sEnctypt mo nga ra 90 ka hiahia koe ki te whakahou ma te whakahau sudo certbot renew, ka whakaara ano i te kaupapa me te whakahau docker-compose restart

Ko tetahi atu whiringa ko te taapiri i tenei raupapa ki te crontab.

Ki taku whakaaro koinei te huarahi ngawari ki te hono SSL ki te Docker Web-app.

PS Kia mahara ko nga tuhinga katoa e whakaatuhia ana i roto i te tuhinga kaore i te mutunga, ko te kaupapa inaianei kei te waahi hohonu o Dev, no reira ka tono ahau kia kaua koe e whakahee i nga whirihoranga - he maha nga wa ka whakarereketia.

Source: will.com

Tāpiri i te kōrero