Nginx配置反向代理并重写URL

First Post:

Last Update:

nginx.conf

1
2
3
4
5
6
7
# ...
location /api {
rewrite /api/(.+)$ /$1 break;
proxy_pass http://localhost:3000 ;
proxy_redirect off;
}
# ...

访问:http://localhost/api,会代理到http://localhost:3000http://localhost:3000路由中无需额外写/api,nginx会自动重写。