1

Hi Stackoverflow community !

i am trying to access to my spring boot app behind nginx reverse proxy in docker swarm architecture. the problem that when i go to http://subdomain.example.com/myapp it redirects me to http://subdomain.example.com/login with 404 no found page instead of the login page on http://subdomain.example.com/myapp/login

Below my nginx configuration

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

    server_name subdomain.example.com www.subdomain.example.com;

    access_log  /var/log/nginx/subdomain.example.com-access.log;
    error_log   /var/log/nginx/subdomain.example.com-error.log;


    location /myapp/ {

        proxy_pass    http://docker_service_name/;

        proxy_set_header    Host               $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-Host   $host;
        proxy_set_header    X-Forwarded-Server $host;
        proxy_set_header    X-Forwarded-Port   $server_port;
        proxy_set_header    X-Forwarded-Proto  $scheme;
        proxy_set_header    X-Forwarded-Prefix /myapp;


        add_header    'Access-Control-Allow-Origin' '*' always;
        add_header    'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
        add_header    'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept' always;
        add_header    'Access-Control-Allow-Credentials' 'true' always;

        }
}

i have added those two lines to my spring boot application.propoerties but keeping redirect to http://subdomain.example.com/login with 404 no found page instead of the login page on http://subdomain.example.com/myapp/login

server.forward-headers-strategy=framework
server.use-forward-headers=true

i tried all those solutions without sucess :

Adding X-Forwarded-Prefix

https://library.humio.com/stable/docs/installation/cluster/nginx-reverse-proxy/

Enable forward headers in Spring boot application.properties.

Running spring boot application behind nginx - missing location prefix when redirect

rewrite URL

https://developpaper.com/nginx-configure-reverse-proxy-to-remove-prefix/

Does someone have a solution for that ?

Best Regards

1 Answer 1

0

I resolved the problem by adding the following line to my application.properties

server.servlet.context-path=/myapp
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.