Nginx反向代理上传大文件失败问题求助
Let's break down the possible issues and actionable fixes since you've already covered the basic client-side body size and timeout settings. Here's what to check next:
1. Ensure client_max_body_size applies to the right scope
You set client_max_body_size 0; in your main nginx.conf, but Nginx lets this parameter be overridden in server or location blocks. Double-check your site-specific config (usually in /etc/nginx/sites-available/ or /etc/nginx/conf.d/) for your photo.domain.com server block:
- Add
client_max_body_size 0;explicitly inside theserverblock or the specificlocationblock that handles the proxy pass to Synology Photos. - Make sure no nested configs are setting a smaller value (like
10M) that would override the global setting.
2. Add proxy-side timeouts (you're missing these critical settings!)
Your current timeout rules only apply to client-Nginx connections, but you need to set timeouts for the Nginx-Synology NAS connection too. Drop these parameters inside your proxy location block:
proxy_connect_timeout 600s; proxy_send_timeout 600s; proxy_read_timeout 600s;
Large file uploads take time to transfer from Nginx to the Synology, so these values need to be long enough to match your upload speed and file size.
3. Check Synology NAS's internal restrictions
Even local uploads work, Synology's own web server (it runs Nginx under the hood) might have limits that trigger when traffic comes through a reverse proxy:
- Open Synology's Control Panel > Application Portal > Reverse Proxy and verify there are no additional body size limits set for your Photos entry.
- Navigate to Synology Photos > Settings > Advanced to confirm the app itself has no global upload size restriction.
- You can also spot-check Synology's internal Nginx configs (in
/usr/syno/etc/nginx/conf.d/) to ensureclient_max_body_sizeis set appropriately there (though local uploads working makes this less likely, it's worth a quick check).
4. Use Nginx error logs to pinpoint the exact issue
This is the most important step. When a large upload fails, check your Nginx error log (typically /var/log/nginx/error.log) for entries around the failure time:
413 Request Entity Too Large: Confirmsclient_max_body_sizeis still not applied correctly.upstream timed out: Means theproxy_read_timeoutor Synology's side is timing out mid-transfer.- Connection reset errors: Points to a firewall or network device dropping the connection unexpectedly.
5. Rule out network/firewall limitations
If logs show unexpected connection drops, check:
- Your router or firewall (both local and cloud-based, like Cloudflare if you use it) for upload file size or connection duration limits.
- Ensure no traffic shaping or QoS rules are throttling large uploads through the reverse proxy.
6. Test incrementally to narrow down the problem
- Start with a file size just above what works, then gradually increase it to find the exact threshold where failures start.
- Temporarily set all timeout values to a very high number (e.g., 1800s = 30 minutes) to rule out timeout-related issues entirely, then adjust back to a reasonable value once it works.
内容的提问来源于stack exchange,提问作者Dan

