E
E
EVOSandru62019-11-08 21:39:54
Nginx
EVOSandru6, 2019-11-08 21:39:54

How to setup https nginx docker container?

Good afternoon,
I bought a hosting, registered ns records, added an A record. To check the correct binding of the domain, I installed nginx, checked the work on port 80 for conditionally domen.ru, Hello Nginx opened.
I'm confused to start with docker.
1) A working version of the config: when access works only from port 80 ( http://domen.ru):

server
{
    listen 80;
    server_name www.domen.ru domen.ru;

    index index.php index.html;
    root /var/www/public;

    location / {
        try_files $uri /index.php?$args;
    }

    location /docs {
        try_files $uri $uri/;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php-fpm:9000; # так называется контейнер с php-fpm
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

2) Option with a problem with https:
server {
    listen 80;
    server_name www.domen.ru domen.ru;
    return 301 https://$host$request_uri;
}

server {
    listen 443;
    server_name www.domen.ru domen.ru;
    charset utf-8;

    index index.php index.html;
    root /var/www/public;
    location / {
        try_files $uri /index.php?$args;
    }
    location /docs {
        try_files $uri $uri/;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    ssl on;
    ssl_certificate /etc/nginx/ssl/fullchain.pem; # определено в volume
    ssl_certificate_key /etc/nginx/ssl/privkey.pem; # определено в volume
}

When accessing https://domen.ru : The following
message is displayed:
Unable to access the site The site domen.ru does not allow you to establish a connection.
Try
the following: Check your Internet connection.
Check your proxy and firewall settings.
ERR_CONNECTION_REFUSED Serts are

generated by certbot and transferred to volume
on the hosting What should I pay attention to in order to solve the problem?
docker-compose.yml
version: '3.7'
services:
  nginx:
    container_name: nginx
    build:
      context: ./
      dockerfile: docker/containers/nginx/${ENV}/Dockerfile
    volumes:
      - ${APP_PATH_HOST}:/var/www
      - ./volumes/ssl:/etc/nginx/ssl
      - ./volumes/log/nginx/:/var/log/nginx/
    ports:
      - 443:443
      - 80:80
    extra_hosts:
      - domen.ru:{ip_address}
  php-fpm:
    container_name: php-fpm
    build: ${CONTAINERS_PATH}/php-fpm
    volumes:
      - ${APP_PATH_HOST}:/var/www
    environment:
      - REDIS_PORT=6379
      - REDIS_HOST=redis
      - DB_CONNECTION=pgsql
      - DB_PORT=5432
      - DB_HOST=pgsql
  php-cli:
    container_name: php-cli
    build: ${CONTAINERS_PATH}/php-cli
    volumes:
      - ${APP_PATH_HOST}:/var/www
    environment:
      - REDIS_PORT=6379
      - REDIS_HOST=redis
      - DB_CONNECTION=pgsql
      - DB_PORT=5432
      - DB_HOST=pgsql
    tty: true
  pgsql:
    container_name: pgsql
    image: postgres:${POSTGRES_VERSION}
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DATABASE=${DB_NAME}
    ports:
      - 54321:5432
    volumes:
      - ${STORAGE_PATH}/postgres:/var/lib/postgresql/data
  node:
    container_name: node
    image: node:${NODE_VERSION}
    volumes:
        - ${APP_PATH_HOST}:/var/www
    working_dir: /var/www
    tty: true

./docker/containers/nginx/prod/Dockerfile
FROM nginx:1.10

ADD ./docker/nginx/prod.conf /etc/nginx/conf.d/default.conf
WORKDIR /var/www

There are definitely certificates in the ./volumes/ssl folder .
Run the following commands on hosting:
$ nmap -sT -p80,443 185.228.233.68
Starting Nmap 7.60 ( https://nmap.org ) at 2019-11-10 14:37 MSK
Nmap scan report for www.domen.ru (185.228.233.68)
Host is up (0.00052s latency) .
PORT STATE SERVICE
80/tcp closed http
443/tcp closed https
Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds
$ lsof -Pni | grep ":80|:443"
Empty output
$ sudo lsof -i -P -n | grep LISTEN
systemd-r 643 systemd-resolve 13u IPv4 15063 0t0 TCP 127.0.0.53:53 (LISTEN)
sshd 871 root 3u IPv4 17768 0t0 TCP *:22 (LISTEN)
sshd 871 root 4u IPv6 17770 0t0 TCP *:22 (
LISTEN)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-11-08
@q2digger

Show the output of the command after running
docker-compose ps
Also check that in the logs of the nginx container, if they are regularly output to stderr for Docker, then
docker-compose logs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question