0

I'm trying to proxy another web server, on localhost:20000, from nginx. This works:

location/ {
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 http://127.0.0.1:20000
}

However if I change it to:

location /myApp {
proxy_set_header..

I can only load the index.html file, all the other .css & .js 404. I can see in the browser's headers that the request for these files are going to mysite.com/jquery.js instead of mysite.com/myApp/jquery.js, so I'm guessing they aren't being proxied at that point which is why they 404. The paths to these URLs are coded relatively (). How do I get this to work. I can't change the paths in the proxied index.html files. Thanks

Edit. The backend webserver is thttpd and it is ancient. Would this effect the set_head Host? Sorry I'm not very familiar with how that layer works.

1
1

First of all, location /myApp {} must be above location {}. Second, what is probably more important, you can serve static files directly, by properly assigning root and adding a secion like this:

location ~* \.(css|jpg|png|gif|jpeg|js|ico|swf|mp3)$ { break; }

If you want to modify the URI instead, this can be helpful, inside location / {} section:

rewrite ^/(.*)$ /myApp/$1 break;

2
  • That would work for what I showed but I dummied it down to get to the root cause. I'm really doing location ~ "^/[\d]{5}"{proxy_pass 127.0.0.1:$1} which is why it's critical to re-write the proxy_set_head Host. Thanks this is better than nothing though.
    – Nimjox
    Sep 24 '15 at 17:13
  • Though even if I did find a way to get the ports static, I think this would route my host page's .css & .js to the wrong place.
    – Nimjox
    Sep 24 '15 at 17:18

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.