Home > Net >  Issue with Auth0/Nginx/Django redirect after login with Nginx Proxy
Issue with Auth0/Nginx/Django redirect after login with Nginx Proxy

Time:02-12

I am using nginx as a proxy to pass to my django app container. I can successfully access the main url but when it passes control back to the django app and logins in the django app container gives it the local url and it doesn't route back to the correct page.

The redirect uri comes in as http://app

site-enabled

upstream app{
    server 0.0.0.0:8888;
}

server {
    listen 8080;
    server_name app-dev.company.net;

    location / {
        # django running in uWSGI
        proxy_pass http://app;
        include uwsgi_params;
        uwsgi_read_timeout 300s;
        client_max_body_size 320m;
        sendfile on;
        proxy_read_timeout 1800;
        proxy_connect_timeout 1800;
        proxy_send_timeout 1800;
        send_timeout 1800;
    }
}

docker-compose.yml

version: "3.9"   
services:
  app:
    image: ecr/app
    container_name: django_app
    ports:
      - 8888
    env_file:
      - dev.env
    volumes:
      - staticfiles:/opt/app/static/
  nginx:
    build: ./nginx
    container_name: django_app
    volumes:
      - staticfiles:/opt/app/static/
    ports:
      - 8080:8080
    depends_on:
      - app
volumes:
  staticfiles:

CodePudding user response:

Your docker-compose / nginx configuration file is full with little errors that could cause this kind of problem - so lets try to remove them.

  • delete the container names if not needed. This will make it easier to understand how to link from one container in another.

  • Where is your NGINX Dockerfile you need to do build ./nginx.

docker-compose

version: "3.9"   
services:
  app:
    image: ecr/app
    ports:
      - 8888
    env_file:
      - dev.env
    volumes:
      - staticfiles:/opt/app/static/
  nginx:
    build: ./nginx
    volumes:
      - staticfiles:/opt/app/static/
    ports:
      - 8080:8080
    depends_on:
      - app
volumes:
  staticfiles:

NGINX Configuration

  • You can not use 0.0.0.0 in your upstream block. Normally I use the service name. In your case app. So please change that to server app:8888; and test it one more time.

  • Location Configuration

You are proxying http traffic to your django app container. There is no need to use uwsgi_read_timeout or include uwsgi_params. In your case a simple http proxy configuration would be enough. For example in all the things you have randomly added to the nginx configuration, one important proxy configuration is missing.

 proxy_pass http://django_app;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header Host $host;
 proxy_redirect off;

Make sure your understand the directives you are using in the NGINX configuration as well as in the docker-compose file, clean up the config files and try again.

  • Related