wordpress的搭建(nginx+php+mysql)和开启多站点模式

  1. 多站点模式选择

    1. 如果希望通过域名的不通来访问不同的子站,那么就需要准备一个域名
    2. 如果希望通过访问的不用的目录来区分子站,那么有无域名都行
  2.  搭建wordpress

    新建一个wordpress用户来运行程序,并且使用下列命令设置为nologin
    
    useradd -s /sbin/nologin wordpress
    
    安装了epel源
    
    yum install -y epel-release
    
    关闭firewalld
    
    systemctl stop firewalld
    
    systemctl disable firewalld
    
    #######安装nginx
    
    yum install nginx
    
    systemctl start nginx
    
    systemctl enable nginx
    
    usermod -a -G nginx wordpress
    
    chmod 770 -R /var/lib/nginx/
    
    ##########安装数据库
    
    yum install mariadb-server -y
    
    systemctl start mariadb
    
    systemctl enable mariadb
    
    登陆数据库创建wordpress的数据库和用户
    
    yum install yum-utils
    
    yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    
    yum-config-manager --enable remi-php72
    
    yum install php-cli php-fpm php-mysql php-json php-opcache php-mbstring php-xml php-gd php-curl
    
    修改/etc/php-fpm.d/www.conf
    
    user = wordpress
    ...
    group = wordpress
    ...
    listen = /run/php-fpm/www.sock
    ...
    listen.owner = wordpress
    listen.group = wordpress
    
    目录的所有组权限为wordpress
    chown -R root:wordpress /var/lib/php
    systemctl restart php-fpm
    systemctl enable php-fpm

    #############################https证书制作

    #如果是想用http就不用制作证书
    #此处准备采用子域名的模式来访问创建的站点,因此随便写个域名 zx.joen.xyz
    #此域名作为主站点,在来一个测试环境,开发环境的域名,test.zx.joen.xyz dev.zx.joen.xyz
    #域名解析,在本地hosts文件里做解析,在服务器/etc/hosts下也做解析

         

 

#域名的证书制作
#生成私钥
openssl genrsa -des3 -out server.pass.key 2048   

#去除私钥中的密码
openssl rsa -in server.pass.key -out server.key

#生成csr(证书签名请求文件)
openssl req -new -key server.key -out server.csr -subj "/C=CN/ST=Shanxi/L=xian/O=jdevops/OU=jdevops/CN=zx.joen.xyz"

#生成自签名的SSL证书
openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.cr

生成如下文件

 

 上传wordpress安装包到tar zxvf wordpress-5.8.1.tar.gz -C /home/wordpress下并解压

修改文件权限 chown -R wordpress:wordpress wordpress

#修改配置文件

cd /home/wordpress/wordpress

cp wp-config-sample.php wp-config.php

打开wp-config.php做如下修改:填写数据库的地址用户密码信息

/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'wordpress' );

/** MySQL database password */
define( 'DB_PASSWORD', 'wordpress' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
 

 修改nginx 的配置文件并 创建出log目录

####修改nignx的运行用户
vim /etc/nginx/nginx.conf
user  wordpress;

####在/etc/nginx/conf.d 下创建wordpress的nginx server
vim wordpress.conf
添加如下:
server {
        listen 80;
        server_name zx.joen.xyz;

        return 301 https://$server_name$request_uri;
    }
server {
        listen 443 ssl;
        server_name zx.joen.xyz;
        ssl_certificate /etc/nginx/ssl/server.crt;
        ssl_certificate_key /etc/nginx/ssl/server.key;
        root /home/wordpress/wordpress;
        index index.php
        access_log /etc/nginx/conf.d/log/access.log;
        error_log /etc/nginx/conf.d/log/error.log;
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
        
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
            expires max;
            log_not_found off;
        }
        #ignored: “-” thing used or unknown variable in regex/rew
        rewrite ^/([_0-9a-zA-Z-]+/)?wp-admin$ /$1wp-admin/ permanent;

        if (-f $request_filename){
            set $rule_2 1;
        }
        if (-d $request_filename){
            set $rule_2 1;
        }
        if ($rule_2 = "1"){
        #ignored: “-” thing used or unknown variable in regex/rew
        }
        rewrite ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) /$2 last;
        rewrite ^/([_0-9a-zA-Z-]+/)?(.*.php)$ /$2 last;
        rewrite /. /index.php last;
}

nginx -t

nginx -s reload   ###配置无问题则直接访问安装即可

 没设置的可以在这里切换

 

3 多站点模式开启

再次编辑 wp-config.php文件

添加 define('WP_ALLOW_MULTISITE', true);

重新登陆下

 站点访问模式二选一,我用的是子域名模式

 可以看到子域名和子目录的访问区别

 根据提示,再次编辑配置文件添加如下内容

 nginx的转发规则已经在上边添加

添加完毕后直接重新登陆即可

 添加新站点

 添加完成后发现数据库中了一些表

 测试访问:

 

 参考:WordPress实现多站点同时管理详细方法【精】 | 森西分享

用nginx+WordPress搭建个人博客全流程 - SegmentFault 思否

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值