I'm setting up a reverse proxy that connects to different localhost ports with different services.

This is the NGINX site configuration:

server {
    root /var/www/;
    index index.html index.php;

    include /etc/nginx/include/php;

        location /Random_Folder {
                rewrite ^/Random_Folder(.*) /$1  break;
                proxy_redirect     off;
                proxy_pass http://localhost:9000;

I can see that by accessing to: "http://myserver.com:80/Random_Folder" the request go to "http://localhost:9000" as it should. But additional resources on the page fail to load (JS, CSS) and they all point to the root document folder "/" instead of "/Random_Folder".

Is there anything in the configuration I'm missing to make this fully functional ?

Thanks !

  • Why not keep random_folder or some other name to identify the requests ? – tovare Jul 26 '15 at 18:59
  • Because I won't be able to redirect to a different localhost port - the proxy_pass is written dynamically and there are situation where there are more than one "location" to a different localhost port – chaser1 Jul 26 '15 at 19:06
  • Ok, but if you rewrite the URL to / then subsequent requests for css and other files will be relative to that URL. You need to write a rule for both / and random_folder to deal with it. – tovare Jul 26 '15 at 19:11
  • Ok, that sound interesting approach - can you elaborate more ? – chaser1 Jul 26 '15 at 19:55
  • Nothing sophisticated, just the same rule for / so that your /my.css goes to the right server. – tovare Jul 26 '15 at 19:58

Your Answer

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

Browse other questions tagged or ask your own question.