Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

171
Views
Docker compose & nginx network hostnames

I have the following configuration:

  • nginx started by a docker compose file acting as reverse proxy // ssl endpoint
  • an application service started by a different docker compose (for modularity reasons) file serving a application
  • reverse_proxy and app_service are connected via the app_network

Since they are connected via the app_network, I am able to address the app_service in the nginx configuration like http://app_service:8080, which is nice because I don't need to expose ports on the app service itself.

Unfortunately, nginx won't start until I brought up the app service container because it checks the existance of the hostname app_service upon startup.

How can I prevent nginx from checking the hostname on startup, maybe causing a Bad Gateway error when trying to connect while app_service is not running yet?

Configuration files for reference:

# reverse proxy docker-compose.yml
version: '3'
services:
  reverse_proxy:
    restart: always
    container_name: reverse_proxy
    image: nginx
    ports:
      - 80:80
      - 443:443
    volumes:
      - /srv/docker/nginx/config:/etc/nginx
      - /srv/ssl:/srv/ssl

    networks:
  default:
    external:
      name: app_network
# application service docker-compose.yml
version: '3'

services:
  app_service:
    restart: always
    container_name: app_service
    image: <my_app_image>

networks:
  default:
    external:
      name: app_network
# nginx config
server {

    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name app.example.com;

    location / {
        proxy_pass http://app_service:8080;
        include proxy.conf;
    }
    ssl_certificate /srv/ssl/<mycert>.crt;
    ssl_certificate_key /srv/ssl/<mykey>.key;
}
9 months ago · Santiago Trujillo
1 answers
Answer question

0

Here is a way that worked for me:



    # nginx config
    server {

        listen 443 ssl http2;
        listen [::]:443 ssl http2;

        server_name app.example.com;

        location / {
            set $upstream app_service:8080;

            proxy_pass $upstream;
            include proxy.conf;
        }
        ssl_certificate /srv/ssl/.crt;
        ssl_certificate_key /srv/ssl/.key;
    }

This results in a 502 Bad Gateway message if the host is unavailable and does not check availability at startup.

9 months ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.