A
A
Alexey Chernyshov2019-04-14 14:04:10
Nginx
Alexey Chernyshov, 2019-04-14 14:04:10

How to run docker on local machine with ssl?

Good afternoon!
I ran into the following problem, which I still can’t solve, namely:
I can’t run docker on a local machine with an ssl certificate.
Example docker-compose.yaml for proxy-nginx:

version: "2"
services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

networks:
  default:
    external:
      name: nginx-proxy

An example of docker-compose.yaml in an application:
version: "3"
services:
  nginx:
    image: nginx:latest
    networks:
      - nginx-proxy
      - default
    expose:
      - 80
      - 443
    volumes:
      - /home/username/ssl:/etc/nginx/certs
      - ./docker/data/log:/var/log/nginx
      - ./docker/conf.d/nginx.conf:/etc/nginx/nginx.conf
      - ./:/var/www/html
    depends_on:
      - httpd
    environment:
      - VIRTUAL_HOST=test.loc

networks:
  nginx-proxy:
    external:
      name: nginx-proxy

I generated an ssl certificate using the command from the article :
openssl req -x509 -out ssl_test.crt -keyout ssl_test.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=test.loc' -extensions EXT -config <( \
   printf "[dn]\nCN=test.loc\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:test.loc\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

Config ./docker/conf.d/nginx.conf:
http {
    ....
    server {
        listen 443 ssl;
        listen 80;
        server_name _;

        ssl_certificate /etc/nginx/certs/ssl_test.crt;
        ssl_certificate_key /etc/nginx/certs/ssl_test.key;

        index index.php index.html;
        .....
   }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fubaro, 2019-04-23
@fubaro

The problem is that you put the certificates in the wrong place.
If you want to use jwilder as a front nginx, then it is he who will accept the ssl connection, that is, it is in him that you need to mount the certificates. And also correctly name them and throw the necessary env vars into the proxied nginx.
Everything is detailed there https://github.com/jwilder/nginx-proxy#ssl-support

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question