我想使用Nginx将请求代理到当前网络接口主机名,例如:
使用URL /catalog/categories/...
到主机名catalog:8080
的URL /categories/...
代理
网址/vitrine/products/...
代理到主机名为vitrine:8080
的网址{
有什么想法吗?
答案 0 :(得分:1)
配置应如下所示:
http {
...
server {
listen 80;
server_name yourdomain;
set $mycatalog catalog:8080;
set $myvitrine vitrine:8080;
}
location ~ ^/catalog/categories/(.*)$ {
proxy_set_header Host $host:$server_port;
proxy_pass http://$mycatalog/categories/$1$is_args$args;
}
location ~ ^/vitrine/products/(.*)$ {
proxy_set_header Host $host:$server_port;
proxy_pass http://$myvitrine/products/$1$is_args$args;
}
}