# Rewrite inside location block before proxy to local port

**URL:** <https://www.ruby-forum.com/t/rewrite-inside-location-block-before-proxy-to-local-port/227137>\
**Category:** NGINX\
**Created:** [March 5, 2013, 12:58pm UTC](https://www.ruby-forum.com/t/rewrite-inside-location-block-before-proxy-to-local-port/227137 "2013-03-05T12:58:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 5, 2013, 12:58pm UTC](https://www.ruby-forum.com/t/rewrite-inside-location-block-before-proxy-to-local-port/227137/1 "2013-03-05T12:58:45Z")

</div>

Hi,

I asked somewhat releated question here:

> <https://serverfault.com/questions/484573/nginx-proxy-to-a-new-vm-without-affect-old-site-enabled-rules>

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  
10.10.0.57 - - [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”

error  
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: 10.10.0.57, server: localhost, request: “GET  
/beta/scm/ HTTP/1.0”, host: “134.74.77.21”

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

Any idea how to resolve this issue?

Thanks!
