Skip to content

Causes and Solutions for 507 Insufficient Storage Error | Disk Space, S3, Cloud Environment

Category: Server / Infrastructure
This article is currently available in Japanese only. We are working on translations.

The "507 Insufficient Storage" error can occur during file uploads or when writing large amounts of data. This error indicates that the server lacks the storage capacity needed to process the request. This article systematically explains the causes of 507 errors, how to check disk capacity, strategies for preventing log bloat, cloud storage capacity management, and monitoring setup.

From disk full to 507 error Storage full → HTTP 507 trigger flow Cause Log bloat (no logrotate) Temp files in /tmp DB data growth S3 bucket quota inode exhaustion df -h: 100% Disk full HTTP 507 Insufficient Storage Fix: logrotate / tmp cleanup / monitoring (Prometheus node_exporter)
Fig 1: Typical flow from storage shortage to 507 error

What is a 507 Error

HTTP 507 Insufficient Storage is a status code defined in RFC 4918 (WebDAV extension). It is returned when the server cannot allocate the storage space needed to complete the request. Originally a status for the WebDAV protocol, it is now also used as a general error for file storage-related issues.

This error is often a temporary state anomaly and can be resolved by freeing up disk space. However, if left unaddressed, it can lead to serious failures such as database write failures, log output stoppage, and application crashes.

Related status Name Differences
413 Content Too Large Request size exceeds the configured limit (server capacity is not a factor)
507 Insufficient Storage Insufficient physical/logical storage capacity on the server
503 Service Unavailable Temporary service outage (may be due to insufficient capacity)

How to check server disk capacity

When a 507 error occurs, first check the server's disk capacity. Use the commands below to identify where disk space is being consumed.

# ファイルシステムごとの使用量を確認
df -h

# 出力例:
# Filesystem      Size  Used Avail Use% Mounted on
# /dev/sda1        50G   47G  3.0G  94% /
# /dev/sdb1       200G  180G   20G  90% /data

# 特定ディレクトリの使用量を確認
du -sh /var/log/
du -sh /var/www/
du -sh /tmp/

# サブディレクトリごとの使用量をソートして表示
du -h --max-depth=1 /var/ | sort -rh | head -20

# inode(ファイル数)の使用状況も確認(容量はあるのにファイルが作れない場合)
df -i

# 大きなファイルを探す(100MB以上)
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5 -rh | head -20

# 最近24時間以内に更新された大きなファイルを探す
find /var -type f -mtime -1 -size +50M -ls 2>/dev/null

Log file size management (logrotate)

One of the most common causes of insufficient disk space is log file bloat. It is not uncommon for access logs, error logs, and application logs to balloon to several GB. Configure Linux's <code>logrotate</code> properly to perform automatic log rotation.

# /etc/logrotate.d/nginx の設定例
/var/log/nginx/*.log {
    daily           # 毎日ローテーション
    missingok       # ログファイルが無くてもエラーにしない
    rotate 14       # 14世代分を保持
    compress        # gzip で圧縮
    delaycompress   # 直近1世代は圧縮しない
    notifempty      # 空のログはローテーションしない
    create 0640 www-data adm  # 新しいログファイルの権限
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] && kill -USR1 $(cat /var/run/nginx.pid)
    endscript
}
# /etc/logrotate.d/app の設定例(アプリケーションログ)
/var/www/app/storage/logs/*.log {
    daily
    missingok
    rotate 7         # 7日分を保持
    compress
    delaycompress
    notifempty
    create 0644 www-data www-data
    maxsize 100M     # 100MB を超えたら日次以外でもローテーション
    dateext          # 日付をファイル名に付与
    dateformat -%Y%m%d
}

# 手動でローテーションを実行(テスト)
sudo logrotate -f /etc/logrotate.d/app

# ドライラン(実行せずに結果を確認)
sudo logrotate -d /etc/logrotate.d/app

# ログのサイズを即座に確認
ls -lhS /var/log/nginx/ | head -10
ls -lhS /var/www/app/storage/logs/ | head -10

Cleaning up the tmp directory

Temporary files, session files, and cache files from file uploads frequently accumulate in the <code>/tmp</code> directory, consuming disk space.

# /tmp の使用量を確認
du -sh /tmp/

# 古い一時ファイルの確認(7日以上前)
find /tmp -type f -mtime +7 -ls | head -20

# 古い一時ファイルを削除(7日以上前のファイル)
find /tmp -type f -mtime +7 -delete

# PHPセッションファイルの確認と掃除
du -sh /var/lib/php/sessions/
find /var/lib/php/sessions/ -type f -mtime +1 -delete

# PHPのアップロード一時ファイルが残っていないか確認
ls -la /tmp/php*

# systemd-tmpfiles を使った自動掃除(systemd環境)
# /etc/tmpfiles.d/cleanup.conf に以下を追加:
# d /tmp 1777 root root 7d
# 上記設定は /tmp 内の7日以上前のファイルを自動削除
# cron で定期的に掃除するスクリプト例
# /etc/cron.daily/cleanup-tmp

#!/bin/bash
# 7日以上前のtmpファイルを削除
find /tmp -type f -mtime +7 -delete 2>/dev/null

# アプリケーションのキャッシュを掃除
find /var/www/app/storage/framework/cache -type f -mtime +3 -delete 2>/dev/null

# 容量を記録
echo "$(date '+%Y-%m-%d %H:%M:%S') - $(df -h / | tail -1)" >> /var/log/disk-usage.log

Capacity limits on S3 and cloud storage

Even when using cloud storage, attention must be paid to capacity limitations and costs. While AWS S3 itself has no bucket capacity limit, cost management and lifecycle policies must be properly configured.

# AWS CLI で S3 バケットのサイズを確認
aws s3 ls s3://my-bucket --recursive --summarize --human-readable | tail -2
# 出力例:
# Total Objects: 152345
# Total Size: 85.3 GiB

# CloudWatch メトリクスでバケットサイズを確認
aws cloudwatch get-metric-statistics \
    --namespace AWS/S3 \
    --metric-name BucketSizeBytes \
    --dimensions Name=BucketName,Value=my-bucket Name=StorageType,Value=StandardStorage \
    --start-time 2026-04-13T00:00:00Z \
    --end-time 2026-04-14T00:00:00Z \
    --period 86400 \
    --statistics Average
// S3 ライフサイクルポリシーの設定例
// 古いファイルを自動的にアーカイブ・削除
{
    "Rules": [
        {
            "ID": "archive-old-uploads",
            "Status": "Enabled",
            "Filter": {
                "Prefix": "uploads/"
            },
            "Transitions": [
                {
                    "Days": 90,
                    "StorageClass": "STANDARD_IA"
                },
                {
                    "Days": 365,
                    "StorageClass": "GLACIER"
                }
            ]
        },
        {
            "ID": "delete-temp-files",
            "Status": "Enabled",
            "Filter": {
                "Prefix": "tmp/"
            },
            "Expiration": {
                "Days": 7
            }
        },
        {
            "ID": "cleanup-incomplete-uploads",
            "Status": "Enabled",
            "Filter": {
                "Prefix": ""
            },
            "AbortIncompleteMultipartUpload": {
                "DaysAfterInitiation": 3
            }
        }
    ]
}
Cloud Services Capacity Limit Per file limit Points to note
AWS S3 Unlimited 5TB Cost management and lifecycle policy configuration are important
Google Cloud Storage Unlimited 5TB Be cautious of increased costs when object versioning is enabled
Azure Blob Storage Unlimited Approximately 4.75 TB (Block Blob) Bandwidth and IOPS limits per account
DigitalOcean Spaces 250GB (plan-dependent) 5GB Be aware of storage capacity limits for your plan

Monitoring Configuration (Threshold Alerts)

Prevention is most important for 507 errors. Set up monitoring to alert when disk usage exceeds a certain threshold.

#!/bin/bash
# /usr/local/bin/disk-alert.sh
# ディスク使用率監視スクリプト

THRESHOLD=80  # 警告しきい値(%)
CRITICAL=90   # 危険しきい値(%)
MAILTO="admin@example.com"

df -h --output=pcent,target | tail -n +2 | while read usage mount; do
    # パーセント記号を除去
    usage_num=$(echo "$usage" | tr -d '%')

    if [ "$usage_num" -ge "$CRITICAL" ]; then
        echo "CRITICAL: ${mount} のディスク使用率が ${usage}% です" | \
            mail -s "[CRITICAL] ディスク容量警告 - $(hostname)" "$MAILTO"
    elif [ "$usage_num" -ge "$THRESHOLD" ]; then
        echo "WARNING: ${mount} のディスク使用率が ${usage}% です" | \
            mail -s "[WARNING] ディスク容量警告 - $(hostname)" "$MAILTO"
    fi
done

# crontab に登録(5分ごとに実行)
# */5 * * * * /usr/local/bin/disk-alert.sh
# Prometheus + node_exporter でのアラート設定例
# /etc/prometheus/alerts/disk.yml

groups:
  - name: disk_alerts
    rules:
      - alert: DiskSpaceWarning
        expr: (1 - node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100 > 80
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "ディスク使用率が80%を超えています"
          description: "{{ $labels.instance }} の {{ $labels.mountpoint }} の使用率が {{ $value }}% です。"

      - alert: DiskSpaceCritical
        expr: (1 - node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100 > 90
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "ディスク使用率が90%を超えています - 即時対応が必要"
          description: "{{ $labels.instance }} の {{ $labels.mountpoint }} の使用率が {{ $value }}% です。"

      - alert: DiskInodeWarning
        expr: (1 - node_filesystem_files_free / node_filesystem_files) * 100 > 80
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "inode使用率が80%を超えています"
# Python での簡易ディスク監視スクリプト
import shutil
import smtplib
from email.mime.text import MIMEText

def check_disk_usage(path='/', warning_threshold=80, critical_threshold=90):
    """ディスク使用率を確認してアラートを送信"""
    total, used, free = shutil.disk_usage(path)

    usage_percent = (used / total) * 100
    free_gb = free / (1024 ** 3)

    print(f"パス: {path}")
    print(f"使用率: {usage_percent:.1f}%")
    print(f"空き容量: {free_gb:.1f} GB")

    if usage_percent >= critical_threshold:
        send_alert(
            level="CRITICAL",
            message=f"{path} の使用率が {usage_percent:.1f}% です。"
                    f"空き容量: {free_gb:.1f} GB"
        )
    elif usage_percent >= warning_threshold:
        send_alert(
            level="WARNING",
            message=f"{path} の使用率が {usage_percent:.1f}% です。"
                    f"空き容量: {free_gb:.1f} GB"
        )

    return usage_percent

def send_alert(level, message):
    """メールアラートを送信"""
    msg = MIMEText(message)
    msg['Subject'] = f"[{level}] ディスク容量アラート"
    msg['From'] = "monitor@example.com"
    msg['To'] = "admin@example.com"

    with smtplib.SMTP('localhost') as server:
        server.send_message(msg)

if __name__ == '__main__':
    check_disk_usage('/')
    check_disk_usage('/data')

Emergency capacity allocation procedure

If a 507 error occurs and the service is down, follow the steps below to quickly free up space.

# 1. まず現状を把握
df -h
du -h --max-depth=1 / | sort -rh | head -10

# 2. 即座に削除できるファイル
# 古いログファイル(圧縮済み)
rm -f /var/log/nginx/*.gz
rm -f /var/log/syslog.*.gz

# パッケージマネージャーのキャッシュ
apt-get clean          # Debian/Ubuntu
yum clean all          # CentOS/RHEL

# 古いカーネル(Ubuntu)
apt-get autoremove --purge

# 3. 大きな不要ファイルを探して削除
find /var -type f -size +100M -mtime +30 -ls
find /tmp -type f -mtime +1 -delete

# 4. ログの即時ローテーション
logrotate -f /etc/logrotate.conf

# 5. journalctl のログを圧縮(systemd環境)
journalctl --vacuum-size=100M
journalctl --vacuum-time=7d

# 6. 削除後の確認
df -h

Test files for this article (free)

  • → <a href="/ja/files/threshold/png/50mb/" class="text-primary-600 dark:text-primary-400 hover:underline">50MB boundary value test PNG</a> — For large file upload verification
  • → <a href="/ja/files/threshold/png/10mb/" class="text-primary-600 dark:text-primary-400 hover:underline">10MB boundary value test PNG</a> — For basic storage write testing
  • → <a href="/ja/files/threshold/" class="text-primary-600 dark:text-primary-400 hover:underline">Boundary Value Test Files</a> — Test files of various sizes
  • → <a href="/ja/files/images/" class="text-primary-600 dark:text-primary-400 hover:underline">Test Images List</a> — For verifying upload functionality

Related articles

  • → <a href="/ja/blog/http-413-error/" class="text-primary-600 dark:text-primary-400 hover:underline">413 Request Entity Too Large Error: Causes and Solutions</a>
  • → <a href="/ja/blog/http-422-error/" class="text-primary-600 dark:text-primary-400 hover:underline">422 Unprocessable Entity Error: Causes and Solutions</a>
  • → <a href="/ja/blog/nginx-upload-config/" class="text-primary-600 dark:text-primary-400 hover:underline">Nginx File Upload Configuration Guide</a>
  • → <a href="/ja/blog/s3-upload-limit/" class="text-primary-600 dark:text-primary-400 hover:underline">Summary of File Upload Limits for AWS S3 and CloudFront</a>