Answer the question
In order to leave comments, you need to log in
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;
}
}
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
}
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
FROM nginx:1.10
ADD ./docker/nginx/prod.conf /etc/nginx/conf.d/default.conf
WORKDIR /var/www
$ nmap -sT -p80,443 185.228.233.68
$ lsof -Pni | grep ":80|:443"
$ sudo lsof -i -P -n | grep LISTEN
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question