Rewrite inside location block before proxy to local port

John Wong gokoproject at
Tue Mar 5 11:58:09 UTC 2013


I asked somewhat releated question here:

Problem arises with one java program. This java program now expects
/beta/scm because it said "/scm not found" in its pretty java error page.
Not nginx 404.

So this is what I have

server {
    rewrite ^/beta(.*)$ $1 last; # strip out the beta

    location /scm {
        proxy_pass http://localhost:8080;
        proxy_redirect default;
        #proxy_set_header Host $http_host;
        #proxy_set_header X-Real-IP $remote_addr;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


So I am guessing, internally, when we proxy to 8080, the web app actually
receives /scm. That makes sense.

Can we rewrite the url back to /beta/scm inside the location?
I tried this            rewrite ^/scm(.*)$ /beta/scm last;

not working at all. Ngninx would throw 404

access - - [05/Mar/2013:06:55:29 -0500] "GET /beta/scm/ HTTP/1.0" 404
570 "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.22 (KHTML, like
Gecko) Chrome/25.0.1364.97 Safari/537.22"

2013/03/05 06:55:29 [error] 14867#0: *1
"/usr/share/nginx/html/beta/scm/index.html" is not found (2: No such file
or directory), client:, server: localhost, request: "GET
/beta/scm/ HTTP/1.0", host: ""

Why we are looking at /usr/share..../index.html/ ?

Any idea how to resolve this issue?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list