2C2G 这个配置应该是学习入门和初期小微网站性价比最高的服务器配置了,1C1G太卡功能多了用不了,预算充足的直接选2C4G最好选4C8G(日常的普通应用算是全能型了),我初期用过2C2G这个经典的配置,把一些折腾记录一下避免后面少走弯路。首选是服务器操作系统的选择,主流的Linux系统稳定性都不错,我从资源(文档资料)方面考虑,优先考虑Debian和Ubunt,我个人选择 Debian 12(习惯了这分支),但 Debian 12 和 13如何选择版本, 在 2C2G 这个低配置环境下当然首选12,对比差异如下:3y4.net
| 对比维度 | ✅ Debian 12 (Bookworm) | Debian 13 (Trixie) |
|---|---|---|
| 核心稳定性 | 久经考验,是 Debian 官方稳定版,公认的“稳如磐石”,生产环境的首选。 | 在2025年8月正式成为稳定版,但在核心组件上引入了较大变动,潜在风险更高。 |
| 软件栈兼容性 | 完美匹配。你计划的软件栈(PHP 8.4, MariaDB 11.8, WP 6.9)均在官方支持列表内,兼容性经过广泛验证。 | 支持PHP 8.4,MariaDB 11.8也已发布适配,但部分插件或脚本可能未充分测试。 |
| 资源占用与性能 | 极致省内存。实测 LEMP 栈空载约 150MB,WordPress 运行后稳定在 350-500MB。 | 资源占用和 Debian 12 基本一致,但内存优势很小。在 2C2G 环境下,其潜在的性能提升无法体现。 |
| 技术引入风险 | 无风险。采用久经考验的 systemd 等组件。 | 中等风险。核心组件变动较多,如 APT 3.0 等,在低配服务器上出现问题排查更困难。 |

一、整套环境定位
- 服务器:2C2G
- 系统:Debian 12
- Web:Nginx
- PHP:8.4(2026 最优生产版)
- 数据库:MariaDB 11.8(LTS,性能 + 省内存)
- 程序:WordPress 6.9
- 目标:不 OOM、速度快、安全、长期稳定
二、所有配置文件路径
/etc/nginx/nginx.conf # Nginx主配置
/etc/nginx/sites-available/default # WP站点配置 /etc/php/8.4/fpm/php.ini # PHP全局配置 /etc/php/8.4/fpm/pool.d/www.conf # PHP-FPM进程配置 /etc/mysql/mariadb.conf.d/50-server.cnf # MariaDB配置 /var/www/html # WordPress目录
三、1. Nginx 主配置 nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 100;
types_hash_max_size 2048;
server_tokens off;
client_max_body_size 50M;
include /etc/nginx/mime.types;
default_type application/octet-stream;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript image/svg+xml;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
四、2. Nginx WordPress 专用站点配置
server {
listen 80;
server_name _;
root /var/www/html;
index index.php index.html;
charset utf-8;
# 静态资源缓存
location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2|woff|ttf|svg)$ {
expires 7d;
add_header Cache-Control "public, max-age=604800";
}
# WordPress 伪静态
location / {
try_files $uri $uri/ /index.php?$args;
}
# PHP 8.4-FPM
location ~ \.php$ {
try_files $fastcgi_script_name =404;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 32k;
fastcgi_buffers 4 32k;
fastcgi_connect_timeout 30s;
fastcgi_send_timeout 30s;
fastcgi_read_timeout 30s;
}
# 安全限制
location ~ /\.ht { deny all; }
location ~* \.(sql|log|bak|config|inc|sh)$ { deny all; }
location = /readme.html { deny all; }
location = /wp-config.php { deny all; }
location ~ ^/wp-includes/(.*\.php)$ { deny all; }
}
五、3. PHP 8.4 php.ini(2C2G 专用)
memory_limit = 256M
max_execution_time = 30 max_input_time = 60 post_max_size = 50M upload_max_filesize = 50M max_file_uploads = 20 date.timezone = Asia/Shanghai expose_php = Off opcache.enable = 1 opcache.enable_cli = 0 opcache.memory_consumption = 192 opcache.interned_strings_buffer = 16 opcache.max_accelerated_files = 10000 opcache.validate_timestamps = 0 opcache.revalidate_freq = 0 opcache.save_comments = 1 opcache.fast_shutdown = 1 realpath_cache_size = 4096k realpath_cache_ttl = 600 disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source
六、4. PHP 8.4-FPM www.conf
pm = dynamic
pm.max_children = 6 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 pm.max_requests = 500 request_terminate_timeout = 30 request_slowlog_timeout = 5 slowlog = /var/log/php8.4-fpm-slow.log
七、5. MariaDB 11.8 2C2G 优化配置
[mysqld]
user = mysql pid-file = /run/mysqld/mysqld.pid socket = /run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci max_connections = 150 max_allowed_packet = 64M wait_timeout = 600 interactive_timeout = 600 # 2C2G 核心内存 innodb_buffer_pool_size = 768M innodb_log_file_size = 256M innodb_log_buffer_size = 16M innodb_flush_log_at_trx_commit = 1 innodb_file_per_table = 1 innodb_flush_method = O_DIRECT innodb_read_io_threads = 8 innodb_write_io_threads = 4 tmp_table_size = 64M max_heap_table_size = 64M query_cache_type = 0 query_cache_size = 0 key_buffer_size = 32M sort_buffer_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 2M join_buffer_size = 2M thread_cache_size = 8 table_open_cache = 2048 table_definition_cache = 2048 log_error = /var/log/mysql/error.log slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 1
八、6. WordPress 6.9 目录权限(Debian 12)
chown -R www-data:www-data /var/www/html
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;
chmod 600 /var/www/html/wp-config.php
九、7. 一键重启 & 自检命令
# 测试配置
nginx -t php8.4-fpm -t # 重启服务 systemctl restart nginx systemctl restart php8.4-fpm systemctl restart mariadb # 开机自启 systemctl enable nginx systemctl enable php8.4-fpm systemctl enable mariadb
十、内存占用预期(2C2G 稳定状态)
- Nginx:30–60 MB
- PHP 8.4-FPM:250–350 MB
- MariaDB 11.8:850–950 MB
- 系统 + 其他:250–350 MB
- 总计:约 1.4G–1.7G 不会 OOM,高峰也稳
2C2G 下 Debian12 + Nginx + PHP8.4 + MariaDB11.8 + WP6.9 是目前性能、安全、支持周期、内存占用比较均衡的组合。