skip to Main Content

I’m developing a docker project with nginx and django services. I’ve django.conf.template parameterised to pass environment variables dynamically depends on environment.

django.conf:

upstream django_app {
  server  ${DJANGO_PRIVATE_IP}:${DJANGO_PORT};
}

server {

  listen  80;
  listen  443 ssl;
  listen  [::]:443 ssl;
  server_name   ${NGINX_SERVER_NAME};

  ssl_certificate /etc/nginx/certs/elitecars_cert.pem;
  ssl_certificate_key /etc/nginx/certs/elitecars_privkey.pem;

  access_log /var/log/nginx/nginx.django.access.log;
  error_log /var/log/nginx/nginx.django.error.log;

  location / {

    proxy_set_header    X-Forwarded-Host   $host;
    proxy_set_header    X-Forwarded-Server $host;
    proxy_set_header    X-Forwarded-For    $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto  $scheme;
    proxy_set_header    X-Real-IP          $remote_addr;
    proxy_set_header    Host               $host;

    proxy_redirect  off;
    proxy_pass  http://django_app;
  }
}

The template works well because i can see the env vars values with more /etc/nginx/conf.d/sites-available/django.conf command

upstream django_app {
  server  django:8000;
}

server {

  listen  80;
  listen  443 ssl;
  listen  [::]:443 ssl;
  server_name   0.0.0.0 127.0.0.1 localhost;
  ...

But when I tried to access through the browser but doesn’t work.

Any idea? Anybody could help me please?

2

Answers


  1. Chosen as BEST ANSWER

    On local and Mac I need to add host.docker.internal IP to /etc/hosts for nginx config file like this:

    127.0.0.1        localhost
    172.17.0.1       localhost
    ...
    

    And solve the problem.


  2. The IP specified in upstream section is incorrect. The correct syntax is:

    upstream django_app {
      server  0.0.0.0:8000;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search