Bảo mật site WordPress
Cấu trúc thư mục
/var/www/domain.com: chứa toàn bộ website, trong đó có:
- file wp-config.php
- Thư mục public chứa bộ cài WordPress. Config Apache trỏ document root về thư mục này. Các file trong thư mục này sẽ chạy, còn các file ngoài thư mục này sẽ không truy xuất được qua trình duyệt.
- Thư mục con content thay cho thư mục wp-content cũ. Dùng cho các plugin cần ghi dữ liệu vào đây.
- Thư mục con modules chứa các plugins.
- Thư mục con templates chứa các themes.
- Thư mục con media chứa các file uploads.
- Thư mục mu-plugins chứa các mã chạy cho site chung (luôn luôn bật).
- Xóa các file license.txt, readme.html
File permission
Để tất cả các thư mục thuộc sở hữu của root.
Đặt chmod 755 cho thư mục, 644 cho file.
Đặt chmod 777 cho thư mục media.
Đặt chmod 444 cho file wp-config.php để chống sửa.
File wp-config.php
- Generate secret key
- Đổi prefix database
- Tắt debug
// Security: moving folders
define('WP_CONTENT_DIR', __DIR__ . '/public/content');
define('WP_CONTENT_URL', '/content');
define('WP_PLUGIN_DIR', __DIR__ . '/public/modules');
define('WP_PLUGIN_URL', '/modules');
define('WPMU_PLUGIN_DIR', __DIR__ . '/mu-plugins');
define('WPMU_PLUGIN_URL', '/mu-plugins'); // Not use
define('WP_LANG_DIR', __DIR__ . '/languages');
define('UPLOADS', 'media');
// Security: disallow theme/plugin edit/install/update
define('DISALLOW_FILE_EDIT', true);
define('DISALLOW_FILE_MODS', true);
// Optimization
define('WP_POST_REVISIONS', false );
define('WP_MEMORY_LIMIT', '128M');
define('EMPTY_TRASH_DAYS', 0);
define('WP_ALLOW_REPAIR', false);
// Optimization: no cron
define('DISABLE_WP_CRON', true);
define('WP_DEBUG', false);
$table_prefix = 'no_default_';
Thư mục mu-plugins
Tạo file themes.php với nội dung sau để đăng ký thư mục chứa theme là public/templates:
<?php register_theme_directory( dirname( __DIR__ ). '/public/templates' );
Sửa đường dẫn
Vào https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ điền mail, rồi vào mail down về, tải lên web, chạy web /domain/folder
