Nginx 413 error uploading Ghost JSON backup
assistant: [Mon Aug 11, 11:15 AM EDT]
Yep—this is Nginx rejecting the upload with a 413 (“payload too large”). Your JSON is ~7 MB, so we just need to raise `client_max_body_size` and give the proxy a longer timeout.
Here’s a tiny helper that:
- bumps the global limit,
- injects generous limits/timeouts into the site’s server block,
- backs up configs under `/home/adam/backups/`,
- tests and reloads Nginx.
Run as your normal user; it uses `sudo` when needed.
```bash
nano ~/nginx-relax-upload.sh && chmod +x ~/nginx-relax-upload.sh && ~/nginx-relax-upload.sh
```
Paste this into the editor:
```bash
#!/usr/bin/env bash
set -euo pipefail
DOMAIN="${1:-myconversationswith.ai}"
LIMIT="${2:-200m}"
READ_TIMEOUT="${3:-600s}"
SEND_TIMEOUT="${4:-600s}"
BODY_TIMEOUT="${5:-60s}"
BACKUP_DIR="/home/adam/backups/nginx-$(date +%F-%H%M%S)"
echo "🛟 Backing up Nginx configs to $BACKUP_DIR"
sudo mkdir -p "$BACKUP_DIR"
sudo cp -a /etc/nginx/nginx.conf "$BACKUP_DIR/nginx.conf"
sudo cp -a /etc/nginx/sites-available "$BACKUP_DIR/sites-available"
# Ensure global limit in http {} block
if ! grep -q "client_max_body_size" /etc/nginx/nginx.conf; then
echo "➕ Adding global client_max_body_size $LIMIT"
sudo sed -i '/http {/a \ client_max_body_size '"$LIMIT"';' /etc/nginx/nginx.conf
else
echo "🔧 Updating global client_max_body_size to $LIMIT"
sudo sed -i 's/^\(\s*client_max_body_size\s*\).*$/\1'"$LIMIT"';/' /etc/nginx/nginx.conf || true
fi
# Find the vhost for the domain
CONF=$(sudo awk -v dom="$DOMAIN" '
/server_name/ && $0 ~ dom {print FILENAME}
' /etc/nginx/sites-available/* 2>/dev/null | head -n1)
if [ -z "${CONF}" ]; then
echo "⚠️ Could not find /etc/nginx/sites-available vhost for $DOMAIN"
echo " Tip: pass domain as first arg: ~/nginx-relax-upload.sh example.com"
exit 1
fi
echo "📝 Updating $CONF"
# Add/replace directives inside server {}
for kv in "client_max_body_size $LIMIT" \
"proxy_read_timeout $READ_TIMEOUT" \
"proxy_send_timeout $SEND_TIMEOUT"…
user: while we are on this subject, tell me about Ghost’s internal body parser limits and elaborate
assistant: [Mon Aug 11, 11:22 AM EDT]
Totally—there are **two “inside Ghost” gates** after Nginx:
1) **JSON body limit (body-parser)**
- Ghost runs on Express and uses a JSON/body parser for ordinary API calls.
- That parser has a **small limit (≈1–2 MB range, varies by version)** to protect memory.
- This limit only affects raw JSON requests (e.g., saving settings, posts via Admin API).
- It **does not** apply to your **Universal Import** when you upload a `.json` or `.zip` file through the UI—that goes through the upload middleware below.
2) **Upload middleware (multipart)**
- The import endpoint uses a streaming multipart parser (e.g., Multer/Busboy).
- It has a **file size cap set in Ghost’s code** (typically in the “tens of MB”—commonly ~50–100 MB depending on version).
- Your **7 MB** export is *well under* Ghost’s internal cap, so when you saw the error, it was almost certainly Nginx (or any proxy/CDN) saying “413: too large.”
### How to check (and optionally raise) Ghost’s internal cap
If you ever want to verify the exact number your build uses:
```bash
cd /var/www/ghost/myconversationswithai/current
# Look for the admin DB import endpoint and its upload limits
grep -RniE "db.*import|multer|busboy|fileSize" core/server 2>/dev/null
```
You’ll find a line that looks like a Multer (or similar) setup with something like:
```
limits: { fileSize: bytes('50mb') }
```
You *can* bump that number and restart Ghost, but:
- It’s **not officially “configurable”**; you’re **patching app code**.
- **Updates will overwrite** this change, so you’d need to reapply it after upgrades.
- Practically speaking, it’s better to just keep a **high Nginx limit** (we set 200 MB) and leave Ghost’s internal defaults alone.
### Other timeouts to keep in mind
Even with size raised, slow links can hit timeouts:
- **proxy_read_timeout / proxy_send_timeout** (Nginx) — we extended those.
- **client_body_timeout** (Nginx) — extended as well.
- Ghost/Node side uses streaming, so you’re rarel…
user: can you tell me what the limits are? 🧐 i'd at least like to know
adam@ns2:~$ nano ~/nginx-relax-upload.sh && chmod +x ~/nginx-relax-upload.sh && ~/nginx-relax-upload.sh
🛟 Backing up Nginx configs to /home/adam/backups/nginx-2025-08-11-112020
➕ Adding global client_max_body_size 200m
📝 Updating /etc/nginx/sites-available/myconversationswith.ai
🧪 nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
🔄 Reloading Nginx
✅ Done. Upload limit: 200m | Timeouts: read/send 600s/600s
Backups are in /home/adam/backups/nginx-2025-08-11-112020
adam@ns2:~$ cd /var/www/ghost/myconversationswithai/current
# Look for the admin DB import endpoint and its upload limits
grep -RniE "db.*import|multer|busboy|fileSize" core/server 2>/dev/null
core/server/api/endpoints/utils/validators/input/images.js:33: const validIconFileSize = (size) => {
core/server/api/endpoints/utils/validators/input/images.js:45: if (!validIconFileSize(frame.file.size)) {
core/server/data/tinybird/scripts/analytics-generator.js:621: const fileSizeMB = (fs.statSync(outputFile).size / (1024 * 1024)).toFixed(2);
core/server/data/tinybird/scripts/analytics-generator.js:623: console.log(`File size: ${fileSizeMB} MB`);
core/server/data/seeders/importers/index.js:36: require('./MembersFeedbackImporter'),
core/server/data/seeders/importers/MembersFeedbackImporter.js:6:class MembersFeedbackImporter extends TableImporter {
core/server/data/seeders/importers/MembersFeedbackImporter.js:11: super(MembersFeedbackImporter.table, knex, transaction);
core/server/data/seeders/importers/MembersFeedbackImporter.js:45:module.exports = MembersFeedbackImporter;
core/server/data/importer/handlers/json.js:33: if (!importData.db || !Array.isArray(importData.db)) {
core/server/data/schema/fixtures/fixtures.json:890: "db": "importContent",
core/server/services/members/importer/MembersCSV…
assistant: [Mon Aug 11, 11:28 AM EDT]
Short version:
- **DB Import (your .json/.zip)** → Ghost uses `multer` in `core/server/web/api/middleware/upload.js` **with no `limits.fileSize` set.** That means **Ghost itself does not cap the upload size** for this endpoint; the real gate is Nginx (now raised to 200 MB) and disk space in `/tmp`.
- **JSON API requests (non-file)** → handled by Express’ JSON/body parser with a **fixed size limit in code** (typically around **1 MB** in recent Ghost). That limit does **not** apply to the Universal Import.
Want to see it in your tree?
```bash
# 1) Multer config (note: no limits.fileSize here)
nl -ba core/server/web/api/middleware/upload.js | sed -n '1,140p'
# 2) Universal import route using that upload middleware
nl -ba core/server/web/api/endpoints/admin/routes.js | sed -n '200,260p'
# 3) JSON body-parser limit Ghost sets for normal API JSON (shows the exact number)
grep -RniE "express\.json\(|bodyParser\.json\(" core/server | head -n 10
grep -RniE "json\(\s*{[^}]*limit" core/server
```
You’ll see something like `multer({ dest: os.tmpdir() })` (no `limits:`), and an Express `json({ limit: '1mb' })` (exact file & value may vary slightly by version).
Other specific caps that *are* enforced in code (unrelated to DB import):
- **Site icon** upload has a tiny limit (check the constant in `core/server/api/endpoints/utils/validators/input/images.js`), plus dimension checks.
- Logos/cover images have their own validators, but again those don’t touch DB import.
Bottom line for your 7 MB export: **Ghost isn’t the limiter**—now that Nginx is relaxed, the import should go through. If you want, I can script a quick “show-my-limits” checker that prints the exact values from your current source.
user: adam@ns2:~$ # 1) Multer config (note: no limits.fileSize here)
nl -ba core/server/web/api/middleware/upload.js | sed -n '1,140p'
# 2) Universal import route using that upload middleware
nl -ba core/server/web/api/endpoints/admin/routes.js | sed -n '200,260p'
# 3) JSON body-parser limit Ghost sets for normal API JSON (shows the exact number)
grep -RniE "express\.json\(|bodyParser\.json\(" core/server | head -n 10
grep -RniE "json\(\s*{[^}]*limit" core/server
nl: core/server/web/api/middleware/upload.js: No such file or directory
nl: core/server/web/api/endpoints/admin/routes.js: No such file or directory
grep: core/server: No such file or directory
grep: core/server: No such file or directory
adam@ns2:~$ cat core/server/api/endpoints/utils/validators/input/images.js
cat: core/server/api/endpoints/utils/validators/input/images.js: No such file or directory
adam@ns2:~$ cat /core/server/api/endpoints/utils/validators/input/images.js
cat: /core/server/api/endpoints/utils/validators/input/images.js: No such file or directory
adam@ns2:~$
assistant: [Mon Aug 11, 11:33 AM EDT]
You ran those greps from `~`—you need to be inside the Ghost app directory again (where `core/server/...` exists). Two ways:
**Quick way**
```bash
cd /var/www/ghost/myconversationswithai/current
```
Then re-run the greps.
**Or use my little inspector (prints the actual limits it finds):**
```bash
nano ~/ghost-limits.sh && chmod +x ~/ghost-limits.sh && ~/ghost-limits.sh
```
Paste this, save, run:
```bash
#!/usr/bin/env bash
set -euo pipefail
APP="${1:-/var/www/ghost/myconversationswithai/current}"
# Auto-detect if the provided path isn't valid
if [ ! -d "$APP/core/server" ]; then
APP="$(sudo find /var/www -maxdepth 5 -type d -path '*/current/core/server' 2>/dev/null | sed 's#/core/server$##' | head -n1)"
fi
if [ -z "${APP:-}" ] || [ ! -d "$APP/core/server" ]; then
echo "❌ Could not locate Ghost app dir. Pass it explicitly: ~/ghost-limits.sh /path/to/current"
exit 1
fi
echo "📍 Ghost app: $APP"
cd "$APP"
echo "— — —"
echo "🔎 Multer upload middleware (file uploads, incl. Universal Import):"
# Show any explicit file size limits in Multer setup
FOUND_MULTER=$(grep -RniE "multer\(|limits\s*:\s*\{|fileSize" core/server 2>/dev/null || true)
if [ -n "$FOUND_MULTER" ]; then
echo "$FOUND_MULTER" | sed 's/^/ /'
# Try to extract fileSize if present
SZ=$(echo "$FOUND_MULTER" | sed -nE 's/.*fileSize[^0-9]*([0-9]+[kKmMgG]?[bB]?).*/\1/p' | head -n1 || true)
if [ -n "${SZ:-}" ]; then
echo " → Multer limits.fileSize detected: $SZ"
else
echo " → No explicit limits.fileSize detected."
fi
else
echo " No explicit Multer limits found (Ghost likely relies on proxy limits)."
fi
echo "— — —"
echo "🔎 JSON body-parser (non-file JSON API):"
FOUND_JSON=$(grep -RniE "express\.json\(|bodyParser\.json\(|json\(\s*\{[^\}]*limit" core/server 2>/dev/null || true)
if [ -n "$FOUND_JSON" ]; then
echo "$FOUND_JSON" | sed 's/^/ /'
LIM=$(echo "$FOUND_JSON" | sed -nE "s/.*json\(\s*\{[^\}]*limit\s*:\s*'([^']+)'.*/\1/p" | head -n1 || tru…
user: Ok, now the site is restored and running very well, but as you remember, we lost the images. I'll start a new chat thread in this project.
adam@ns2:~$ nano ~/ghost-limits.sh && chmod +x ~/ghost-limits.sh && ~/ghost-limits.sh
📍 Ghost app: /var/www/ghost/myconversationswithai/current
— — —
🔎 Multer upload middleware (file uploads, incl. Universal Import):
core/server/api/endpoints/utils/validators/input/images.js:33: const validIconFileSize = (size) => {
core/server/api/endpoints/utils/validators/input/images.js:45: if (!validIconFileSize(frame.file.size)) {
core/server/data/tinybird/scripts/analytics-generator.js:621: const fileSizeMB = (fs.statSync(outputFile).size / (1024 * 1024)).toFixed(2);
core/server/data/tinybird/scripts/analytics-generator.js:623: console.log(`File size: ${fileSizeMB} MB`);
core/server/services/koenig/node-renderers/file-renderer.js:47: <a href="${escapeHtml(options.postUrl)}" class="kg-file-meta"><span class="kg-file-name">${escapeHtml(node.fileName)}</span> • ${bytesToSize(node.fileSize)}</a>
core/server/services/koenig/node-renderers/file-renderer.js:96: const filesize = document.createElement('div');
core/server/services/koenig/node-renderers/file-renderer.js:97: filesize.setAttribute('class', 'kg-file-card-filesize');
core/server/services/koenig/node-renderers/file-renderer.js:98: filesize.textContent = node.formattedFileSize || '';
core/server/services/koenig/node-renderers/file-renderer.js:101: metadata.appendChild(filesize);
core/server/web/api/middleware/upload.js:59:const upload = multer({dest: os.tmpdir()});
core/server/web/admin/controller.js:37: // `sendFile` by default uses filesize+lastmod date to generate an etag.
core/server/web/admin/controller.js:38: // That doesn't work for admin templates because the filesize doesn't change between versions
→ Multer limits.fileSize detected: 1024
— — —
🔎 JSON body-parser …
assistant: [Mon Aug 11, 11:36 AM EDT]
Nice—glad the restore worked 👌
About those limits (based on the files you just surfaced):
- **DB import (file upload via Multer):**
`core/server/web/api/middleware/upload.js` shows `multer({ dest: os.tmpdir() })` **with no `limits.fileSize`**, so **Ghost doesn’t set a file-size cap here**. The gate is your proxy (Nginx—now 200 MB) and free space in `TMPDIR` (default `/tmp`).
*Note:* the “1024” my helper printed was a false positive from the image validator math (e.g., `200 * 1024` bytes), **not** a Multer cap.
- **JSON body parser (non-file API):**
You’ve got explicit `bodyParser.json({ limit: '50mb' })` across admin/content/members routes, and one path at `5mb`. So regular JSON payloads >50 MB get rejected, but **this does not affect the Universal Import**.
- **Image/icon validators (not related to DB import):**
- `.ico` must be square ≥60×60 and **≤200 kB**.
- Icons (`.jpg/.webp/.svg/.png`) ≥60×60 and **≤20 MB**, with max dimension 1000 px for icons.
These checks are per-file rules, not global upload limits.
### Optional hardening for big imports
If you ever push huge imports, make sure temp space won’t choke:
```bash
# find the Ghost service name
systemctl list-units | grep -i ghost
# create a bigger temp dir and give it to the Ghost user (adjust user if needed)
sudo mkdir -p /home/adam/tmp
sudo chown ghost-mcwai:ghost-mcwai /home/adam/tmp
# add a systemd override to point TMPDIR there
sudo systemctl edit <ghost-service-name>
# then in the editor:
# [Service]
# Environment=TMPDIR=/home/adam/tmp
sudo systemctl daemon-reload
sudo systemctl restart <ghost-service-name>
```
Bottom line for you: **DB import has no Ghost-side size cap; Nginx + tmp space are the real constraints.** Your current setup (200 MB + long timeouts) is plenty for that 7 MB export. We’ll tackle the images in the new thread.
Showing first 9 of 12 messages. View the full conversation at https://mcwai.org/ai-conversation/nginx-413-error-uploading-ghost-json-backup