我正在使用码头群。我在 API 前面放置了一个 nginx 容器以进行缓存。由于每次部署 API 时,它都会创建一个新的内部 IP,因此我根据 swarm 文档使用我的服务tasks.api 的名称。下面是我的位置块
proxy_cache_path /var/cache/nginx/ta_api levels=1:2 keys_zone=api_cache:10m max_size=10g
inactive=60m use_temp_path=off;
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://tasks.api:10010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_buffering on;
proxy_cache api_cache;
proxy_cache_bypass $http_upgrade;
# Add header to see if response was cached
add_header X-Cache-Status $upstream_cache_status;
# Allow one cache-update request at a time sent to an origin server.
proxy_cache_lock on;
# Permit revalidation of stale cached responses. …Run Code Online (Sandbox Code Playgroud)