0

I have an application sitting behind a nginx and obviously not working as desired. So i tried to replicate in my local environment.

Background The webapplication is running fine on its own and returns a /static/index.html as the default page. e.g. on accessing http://localhost:7777/ returns /static/index.html and all works fine. {http://localhost:7777/static/index.html}

Problem When i try to access the same app behind a proxy,it doesn't work. On accessing http://localhost/app { the localhost is name of the server default in nginx } the app returns as usual /static/index.html and gets rerouted tp http://localhost/static/index.html and returns 404.

Desired situation Even if the app is behind a proxy, i should be able to see the app. Instead of http://localhost/static/index.html the URL should be similar to http://localhost/localhost:7777/static/index.html

nginx.conf

server {
    listen       80;
    server_name  localhost;

   location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location /app/ {
            proxy_pass http://localhost:7777/;
    proxy-redirect off;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_buffering off;
            client_max_body_size 0;
            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_pass_header       Set-Cookie;
            proxy_pass_header       P3P;
    }

Any ideas how can this be achieved?

1

If you limit the proxying, as per your nginx.conf, to location /app/, you shouldn't be surprised that /static/index.html doesn't get proxied. Add a

proxy_pass http://localhost:7777/;

to location / and see what happens then.

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.