0

I've some problems. I have service main.example.com based on Django framework and service service.example.com based on fastAPI. In service.example.com absent User authentication. To get access, I use Django session id. In sub-service when user request page, fastAPI check Django session id in Cookies. That is, if the user is not authorized in Django, then he will not get into service.example.com. The service checks endpoint main.example.com/api/verify_session and it return client info. Also I have main.example.com/link_to_redirect to open my sub-service. When I follow the link, in theory I pass Cookies with id session from Django to the second service and successfully enter in sub-service. On a local server all works without SSL, but with the use of configuration below the cookies are not transmitted in the redirect. wrong cookies. In local version without SSL service.example.com I get session_id, client_id, auth_token

Container 1 :

server {
    listen 80;
    server_name main.example.com;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }

}

server {
    listen 443 ssl;
    server_name main.example.com;
    set $dev 192.168.100.200;
    proxy_cookie_flags ~ secure httponly samesite=None;

    ssl_certificate /etc/letsencrypt/live/main.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/main.example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;


    location / {
        proxy_pass http://$dev:5005;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Host $http_host;
        }

    location /link_to_redirect {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Cookie $http_cookie;
        rewrite ^ https://service.example.com/summary/ permanent;
        }

}

Container 2 :

server {
    listen 80;
    server_name service.example.com;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }

}

server {
    listen 443 ssl;
    server_name service.example.com;


    ssl_certificate /etc/letsencrypt/live/service.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/service.example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    proxy_cookie_flags ~ secure httponly samesite=None;

    location / {

      proxy_pass http://192.168.100.200:8082;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-NginX-Proxy true;
      proxy_set_header Host $http_host;
      proxy_set_header Cookie $http_cookie;
    }
}

I think that main problem consists in SSL directive nginx and I have no ideas how to fix it.

Thanks for all answers.

Keyvan Soleimani
  • 606
  • 2
  • 4
  • 16
Edgar
  • 1
  • 1

0 Answers0