在CentOS中搭建由nginx反代和Apache2作为后端的Wordpress

9 min read
  1. 首先安装必要的软件包

在终端中运行以下命令:

sudo yum install epel-release
sudo yum install nginx httpd mariadb-server php php-mysqli php-fpm php-curl php-gd php-mbstring php-xml php-xmlrpc php-opcache
  1. 配置MariaDB数据库

在终端中运行以下命令:

sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation

按照提示输入管理员密码,然后设置其他选项。

  1. 配置nginx反代

创建一个新的nginx配置文件,在终端中运行以下命令:

sudo nano /etc/nginx/conf.d/wordpress.conf

将下面的内容复制到文件中:

server {
    listen 80;
    server_name your_domain.com;
    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

然后保存并关闭文件。

重新加载nginx配置,在终端中运行以下命令:

sudo systemctl restart nginx
  1. 配置Apache2后端

编辑Apache2配置文件,在终端中运行以下命令:

sudo nano /etc/httpd/conf/httpd.conf

找到下面的行,并将其更改为:

Listen 8080

然后保存并关闭文件。

  1. 下载和安装WordPress

在终端中运行以下命令:

cd ~
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
sudo cp -R ~/wordpress/* /var/www/html/
sudo chown -R apache:apache /var/www/html/
sudo chmod -R 755 /var/www/html/
  1. 配置WordPress

在浏览器中访问http://your_domain.com/wp-admin/install.php,按照提示设置WordPress。

  1. 完成

现在,您已经成功地在CentOS中搭建由nginx反代和Apache2作为后端的WordPress。