> ## Content Index
> Fetch the complete content index at: https://sleepyforest.magicbytes.top/llms.txt
> Use this file to discover other available public pages before exploring further.

# Nginx - make proxy_pass work with URI
- URL: https://sleepyforest.magicbytes.top/nginx-make-proxy-pass-work-with-uri/
- Published: 2021-08-24T08:11:11.000Z
- Updated: 2021-10-03T02:32:00.000Z
- Description: nginx workaround: I wanna use proxy_pass with URI!
- Author: Betty
- Tags: Tech, 笔记, #Import 2026-08-29 09:17

> nginx: \[emerg\] "proxy\_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit\_except" block

When you are using regular expression in location, or use if, `nginx -t` will say this.

```
# not working versions
location ^~ /api/{
    proxy_pass http://localhost:3000/api/;
}

location / {
    if($host = a.domain.com){
        proxy_pass http://localhost:1234/a/;
    }
}

```

Workaround: use rewrite

```
location / {
    if($host = a.domain.com){
        rewrite ^ /a$1;
        proxy_pass http://localhost:1234;
    }
}

```