rpm -ivh https://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh https://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum update -y
yum install -y nginx php-fpm php-mysql mysql-server \
php-mbstring php-gd php-pear php-mcrypt php-mhash \
php-eaccelerator php-suhosin php-tidy php-curl
chkconfig nginx on
chkconfig mysqld on
chkconfig php-fpm on
service nginx start
service mysqld start
service php-fpm start
mysqladmin -u root password 'StrongRootPass!'
mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost' IDENTIFIED BY 'WpPassw0rd!';
FLUSH PRIVILEGES;
EXIT;
vim /etc/php-fpm.d/www.conf
# 找到並修改:
user = nginx
group = nginx
# 原為 apache
# 可選:調整進程模型
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
# 重啟
service php-fpm restart
vim /etc/nginx/conf.d/wordpress.conf
server {
listen 80;
server_name your-domain.com;
root /usr/share/nginx/html/wordpress;
index index.php index.html;
access_log /var/log/nginx/wordpress_access.log;
error_log /var/log/nginx/wordpress_error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param HTTPS off;
}
# 安全:禁止存取敏感檔案
location ~* \.(htaccess|htpasswd|ini|log|sh|sql|bak)$ {
deny all;
}
location ~ /\. {
deny all;
}
}
# 部署 WordPress 程式碼
mkdir -p /usr/share/nginx/html/wordpress
cd /usr/local/src
wget https://wordpress.org/latest.tar.gz
tar zxvf latest.tar.gz
cp -r wordpress/* /usr/share/nginx/html/wordpress/
chown -R nginx:nginx /usr/share/nginx/html/wordpress
# 重啟 Nginx
nginx -t && service nginx restart
https://your-domain.com/certbot --nginx 或購買商業憑證)。server 區塊加入 listen 443 ssl;、ssl_certificate、ssl_certificate_key。return 301 https://$host$request_uri;。wp-config.php 加入 define('FORCE_SSL_ADMIN', true);。利用 YUM 官方源快速構建 LNMP,核心調整點:PHP-FPM 用戶改為 nginx、Nginx try_files 支援固定連結、MySQL utf8mb4、權限統一歸屬 nginx。配合 Let's Encrypt 自動續簽,即可獲得安全、高效、易維護的 WordPress 生產環境。