0

I have a ReactJS based web app being served by nginx on /. This web app contacts a web service running on Tomcat which is running on port 8443 on the same machine. I have set up a proxy_pass on nginx to pass any request received on /APIServer to the Tomcat server.

The proxy pass sends the requests on /APIServer successfully to the Tomcat server. But the problem is that Tomcat provides a new JSESSIONID value for each request from the web app. Every response from Tomcat has a Set-Cookie header with a new JSESSIONID while there is no Cookie header sent from the client for each request after the first.

My nginx config is as follows:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html/analytics-ui;

    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location /APIServer/ {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header Access-Control-Allow-Origin *;
        proxy_redirect off;
        proxy_pass https://127.0.0.1:8443/;
    }
}

I have added the proxy headers after researching how to resolve this issue, but so far none of the solutions have worked. Tomcat still provides new JSESSIONIDs for each request from the web app. This causes issues in the web app for functionality such as login and authorization.

The API on the Tomcat server works if I call it directly using Postman or a web browser.

Is there something I am overlooking or is there any additional configuration required to get this to work?

Thanks.

0

Ok, I am a klutz.

The reason this wasn't working was because I wasn't using SSL on nginx while Tomcat was using SSL. I set up SSL in nginx and now it works as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.