0

I am using jwilder/nginx-proxy, i wrote a custom.conf for supporting my custom-routing.

upstream service-a {
    server web:8001;
}
upstream service-b {
    server jobrecommendation.web:8002;
}
server {
    listen 80;

    location /site-alive {
        return 200 'site-alive!';
        add_header Content-Type text/plain;
    }
    location /job-recommendation/ {
       proxy_pass http://service-b;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $host;
       proxy_redirect off;
    }
    location / {
       proxy_pass http://service-a;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $host;
       proxy_redirect off;
    }
}

It is working for http but not in https. Now i am stuck as my ssl certificate is getting generated by jwilder/docker-letsencrypt-nginx-proxy-companion.

My idea was to modify the custom.conf file like this,

upstream service-a {
    server web:8001;
}
upstream service-b {
    server jobrecommendation.web:8002;
}
server {
    listen 80;
    listen 443 ssl http2;
    ssl_session_tickets off;
    ssl_certificate /etc/nginx/certs/example.com/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/example.com/key.pm;

    location /site-alive {
        return 200 'site-alive!';
        add_header Content-Type text/plain;
    }
    location /job-recommendation {
       proxy_pass http://service-b;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $host;
       proxy_redirect off;
    }
    location / {
       proxy_pass http://service-a;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $host;
       proxy_redirect off;
    }
}

but it doesn't seem to be working as the ssl certificates is not found there, although after the container creation it exists.

my docker-compose file:

version: '3.7'

services:
  nginx-proxy:
    container_name: nginx-proxy
    build: ../../nginx
    restart: always
    ports:
      - 443:443
      - 80:80
    volumes:
      - certs:/etc/nginx/certs
      - html:/usr/share/nginx/html
      - vhost:/etc/nginx/vhost.d
      - /var/run/docker.sock:/tmp/docker.sock:ro
    depends_on:
      - web

  nginx-proxy-letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    environment:
      - NGINX_PROXY_CONTAINER=nginx-proxy
      - NGINX_DOCKER_GEN_CONTAINER=nginx-proxy
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - certs:/etc/nginx/certs
      - html:/usr/share/nginx/html
      - vhost:/etc/nginx/vhost.d
      - acme:/etc/acme.sh
    depends_on:
      - nginx-proxy

volumes:
  certs:
  html:
  vhost:
  acme:

and the docker file for nginx:

FROM jwilder/nginx-proxy:0.9
COPY vhost.d/default /etc/nginx/vhost.d/default
COPY custom.conf /etc/nginx/conf.d/custom.conf

what seems to be the problem/possible solution for this?

  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Aug 01 '22 at 22:57

0 Answers0