Config help - Reverse Proxy for Virtual Directories

Igor Sysoev is at rambler-co.ru
Tue Feb 24 12:40:37 MSK 2009


On Thu, Feb 19, 2009 at 10:52:07PM -0700, Gavin Kistner wrote:

> I'm trying to get nginx to do the following (among other things):
> 
> If the URL matches /ObjJob/YYY
> 	if exists /var/www/phrogz.net/ObjJob/public/YYY, serve it statically
> 	otherwise proxy it to http://localhost:9901/YYY #no ObjJob
> 
> If the URL matches /SubSite2/ZZZ
> 	if exists /var/www/phrogz.net/SubSite2/public/ZZZ, serve it 
> 	statically
> 	otherwise proxy it to http://localhost:9902/ZZZ #no SubSite2
> 
> If the URL doesn't match any of the above (/VVV) then
> 	if exists /var/www/phrogz.net/Phrogz/public/VVV, serve it statically
> 	otherwise proxy it to http://localhost:9900/VVV
> 
> My current config can be seen here:
> http://pastie.org/394796
> 
> The following URLs work as desired:
>   http://localhost/static.css # serves from /var/www/phrogz.net/ 
> Phrogz/public/static.css
>   http://localhost/ # proxies to :9900 properly
>   http://localhost/dynamic # proxies to :9900 properly
> 
>   http://localhost/ObjJob/common.css # serves from /var/www/ 
> phrogz.net/ObjJob/public/common.css
> 
> # The following 2 'work', but leave "ObjJob" at the front
> # of the path on the far side of the proxy; ideally I would like
> # the receiving process to think it's the only application around
> # with no knowledge of the "ObjJob" prefix.
>   http://localhost/ObjJob # proxies to :9901 properly
>   http://localhost/ObjJob/ # proxies to :9901 properly
> 
> My main problem, however, is that this fails:
>   http://localhost/ObjJob/dynamic
> 
> I get an nginx 404, with this in the error log:
> open() "/var/www/phrogz.net/ObjJob/public/languages" failed (2: No  
> such file or directory), client: 127.0.0.1, server: localhost,  
> request: "GET /ObjJob/languages HTTP/1.1", host: "localhost"
> 
> How can I fix my configuration to get this to work?

    server {
        listen       80;
        server_name  localhost;

        access_log  logs/phrogz_access.log main;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;

        location / {
            root /var/www/phrogz.net/Phrogz/public;
            error_page  404 = @9900;
        }

        location /ObjJob {
            alias /var/www/phrogz.net/ObjJob/public;
            error_page  404 = @9901;
        }

        location /SubSite2 {
            alias /var/www/phrogz.net/ObjJob/public;
            error_page  404 = @9902;
        }

        location @9900 {
            proxy_pass http://localhost:9900;
        }

        location @9901 {
            proxy_pass http://localhost:9901;
        }

        location @9902 {
            proxy_pass http://localhost:9902;
        }

        location /js {
            root /var/www/phrogz.net/;
            autoindex  on;
        }

        location /svg {
            root /var/www/phrogz.net/;
            autoindex  on;
        }

    }

-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list