Nginx 部署与配置
本页以 api.example.com 为例,讲解 Nginx 反向代理 PocketBase 的推荐配置(包含 WebSocket、上传大小、超时等)。
1) PocketBase 仅监听本机
Section titled “1) PocketBase 仅监听本机”./pocketbase serve --http=127.0.0.1:80902) Nginx 反向代理(HTTP)
Section titled “2) Nginx 反向代理(HTTP)”server { listen 80; server_name api.example.com;
location / { proxy_pass http://127.0.0.1:8090; proxy_http_version 1.1;
# WebSocket / Realtime proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme;
# Large uploads client_max_body_size 100m;
# Long connections (realtime / long polling) proxy_read_timeout 3600; proxy_send_timeout 3600; }}3) 常见问题
Section titled “3) 常见问题”上传失败 / 413 Request Entity Too Large
Section titled “上传失败 / 413 Request Entity Too Large”把 client_max_body_size 提高(例如 100m),同时确认 PocketBase 的文件字段限制与你的反向代理一致。
Realtime 不稳定
Section titled “Realtime 不稳定”确保包含 Upgrade / Connection 头,并提高 proxy_read_timeout。