0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WordPressを安全にインストール・運用するためのファイル構成と設定

Posted at

WordPressを安全にインストール・運用するためのファイル構成と設定は、セキュリティの基本かつ重要なステップです。以下では、推奨される安全なファイル構成とあわせて、セキュリティ対策も含めて具体的に説明します。

✅ 推奨ファイル構成(セキュア運用)
plaintext
Copy
Edit
/public_html/(または /var/www/html/)
├── index.php
├── wp-config.php(←できればルートの1つ上に移動)
├── .htaccess(←ファイル保護の要)
├── wp-content/
│ ├── plugins/
│ ├── themes/
│ └── uploads/(←画像等が保存される。アクセス制限推奨)
├── wp-includes/
├── wp-admin/
└── その他WordPressコアファイル
🔐 セキュリティ対策付きの構成ポイント

  1. wp-config.php の移動(可能なら)
    説明:このファイルにはDBのパスワードなどが記述されています。

対策:wp-config.php を WordPress インストールディレクトリの1階層上に移動可能です(WordPressが自動で読み込みます)。

例:

plaintext
Copy
Edit
/home/youruser/
├── wp-config.php ← ← ← ← ここに移動
└── public_html/
├── wp-admin/
└── ...
2. .htaccess でのアクセス制限(Apacheの場合)
✅ wp-config.php などへのアクセス遮断:
apache
Copy
Edit

order allow,deny
deny from all

✅ /wp-content/uploads の実行制限(PHPなど)
apache
Copy
Edit

php_flag engine off
Options -ExecCGI

3. wp-content 配下の分離と保護
アップロードファイル(写真など) は wp-content/uploads に保存される

直接URLでアクセスできないように以下のような制限を .htaccess に追加:

apache
Copy
Edit

Order Deny,Allow
Deny from all

4. WordPress以外のファイル・ディレクトリ制限
ディレクトリ一覧を非表示化

apache
Copy
Edit
Options -Indexes
404で返すだけの robots.txt 限定的クロール設定

plaintext
Copy
Edit
User-agent: *
Disallow: /wp-admin/
Disallow: /wp-includes/
Disallow: /wp-content/plugins/
5. パーミッションの見直し
ファイル・ディレクトリ 推奨パーミッション 説明
ディレクトリ(全体) 755 実行権限が必要
ファイル(全体) 644 書き込み禁止(他人)
wp-config.php 600(or 640) 管理者のみ読み込み

  1. 管理画面・ログインURL対策(推奨プラグイン)
    ログインURL変更:WPS Hide Login

2段階認証:Wordfence Security、WP 2FA

ファイル変更検出:Sucuri Security

📦 補足:セキュリティ強化に向けた運用方針
項目 推奨事項
自動更新 コア・プラグインは自動更新を有効化する(安全な範囲で)
バックアップ 外部ストレージ(例:Dropbox, Google Drive)に定期保存
管理者ユーザー名 adminは絶対に使わない(推測されやすい)
SSL(HTTPS) Let’s Encrypt などで必ず常時SSL化

✅ まとめ:安全なWordPressファイル構成ポイント
wp-config.php を可能なら上階層へ移動

.htaccess で 重要ファイルとアップロードディレクトリの保護

アップロード画像には直接アクセス制限やウォーターマークなど追加保護

ファイル/ディレクトリのパーミッションを最小限に

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?