Using Nginx
Using Nginx
This document shows how to launch multiple vLLM serving containers and use Nginx to act as a load balancer between the servers.
Build Nginx Container
This guide assumes that you have just cloned the vLLM project and you're currently in the vllm root directory.
export vllm_root=`pwd`Create a file named Dockerfile.nginx:
FROM nginx:latest
RUN rm /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]Build the container:
docker build . -f Dockerfile.nginx --tag nginx-lbCreate Simple Nginx Config file
Create a file named nginx_conf/nginx.conf. Note that you can add as many servers as you'd like. In the below example we'll start with two. To add more, add another server vllmN:8000 max_fails=3 fail_timeout=10000s; entry to upstream backend.
Build vLLM Container
cd $vllm_root
docker build -f docker/Dockerfile . --tag vllmIf you are behind proxy, you can pass the proxy settings to the docker build command as shown below:
cd $vllm_root
docker build \
-f docker/Dockerfile . \
--tag vllm \
--build-arg http_proxy=$http_proxy \
--build-arg https_proxy=$https_proxyCreate Docker Network
docker network create vllm_nginxLaunch vLLM Containers
Notes:
- If you have your HuggingFace models cached somewhere else, update
hf_cache_dirbelow. - If you don't have an existing HuggingFace cache you will want to start
vllm0and wait for the model to complete downloading and the server to be ready. This will ensure thatvllm1can leverage the model you just downloaded and it won't have to be downloaded again. - The below example assumes GPU backend used. If you are using CPU backend, remove
--gpus device=ID, addVLLM_CPU_KVCACHE_SPACEandVLLM_CPU_OMP_THREADS_BINDenvironment variables to the docker run command. - Adjust the model name that you want to use in your vLLM servers if you don't want to use
Llama-2-7b-chat-hf.
Note
If you are behind proxy, you can pass the proxy settings to the docker run command via -e http_proxy=$http_proxy -e https_proxy=$https_proxy.
Launch Nginx
docker run \
-itd \
-p 8000:80 \
--network vllm_nginx \
-v ./nginx_conf/:/etc/nginx/conf.d/ \
--name nginx-lb nginx-lb:latestVerify That vLLM Servers Are Ready
docker logs vllm0 | grep Uvicorn
docker logs vllm1 | grep UvicornBoth outputs should look like this:
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)