# How to specify proxy URI (Path) for mitmproxy - Rewrite path

**URL:** <https://discourse.mitmproxy.org/t/how-to-specify-proxy-uri-path-for-mitmproxy-rewrite-path/1599>\
**Category:** help\
**Created:** [June 29, 2019, 11:08am UTC](https://discourse.mitmproxy.org/t/how-to-specify-proxy-uri-path-for-mitmproxy-rewrite-path/1599 "2019-06-29T11:08:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stmx38](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@stmx38](https://discourse.mitmproxy.org/u/stmx38)\
**Post date:** [June 29, 2019, 11:08am UTC](https://discourse.mitmproxy.org/t/how-to-specify-proxy-uri-path-for-mitmproxy-rewrite-path/1599/1 "2019-06-29T11:08:26Z")

</div>

Hello,

We are trying to analyze traffic between our Nginx reverse proxy and Web server:  
`Client --> Internet --> Nginx --> Webserver`  
`Client --> Internet --> Nginx --> mitmproxy --> Webserver`

If I understand correctly we should use a reverse mode:

`mitmproxy --listen-port 8080 --mode reverse:http://webserver:8081`

But our clients send requests with one URI which is routed by Nginx to Webserver to another URI:  
`client --> nginx/api/input --> webserver/api/output`

Probably we may achieve this by using a script. We tried this one:

> ```
> def request(context, flow):
> if flow.request.path == '/api/input':
> flow.request.path = '/api/output'
> 
> ```

`mitmproxy --listen-port 8080 --mode reverse:http://webserver:8081 --script rewrite_path.py`

But it doesn’t do the work, we still see:

`POST http://webserver:8081/api/input`

1. How proxy URI can be specified in mitmproxy?
2. If with the script only where we may find a sample?
3. How mitmproxy may be started in reverse mode with the script, should we specify a mode in such case?

Thank you!

---

<div class="post-metadata">

**Author:** ![stmx38](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@stmx38](https://discourse.mitmproxy.org/u/stmx38)\
**Post date:** [July 7, 2019, 4:15pm UTC](https://discourse.mitmproxy.org/t/how-to-specify-proxy-uri-path-for-mitmproxy-rewrite-path/1599/2 "2019-07-07T16:15:51Z")

</div>

We did it on Nginx side:

```auto
    upstream webserver {
      192.168.0.2:8080;
    }
    upstream mitmproxy {
      192.168.0.3:8080;
    }
   
      location /api/input {

        proxy_pass http://webserver/api/output;

        set $upstream mitmproxy;
        if ($remote_addr ~ (1.1.1.1|8.8.8.8)) {

          proxy_pass http://$upstream/api/output;

        }
      }

```

All clients go to the webserver and only 1.1.1.1 and 8.8.8.8 via mitmproxy:

```auto
mitmweb --no-web-open-browser \
        --web-iface 0.0.0.0 \
        --web-port 8081 \
        --listen-host 0.0.0.0 \
        --listen-port 8080 \
        --mode reverse:http://192.168.1.3:8080

```
