Rewrite inside location block before proxy to local port


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
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
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”
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
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?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs