4.31 yum安装nginx
编辑yum仓库: vi /etc/yum.repos.d/nginx.repo
按照官方帮助文档,将以下内容复制粘贴并保存: [nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
安装nginx: yum install -y nginx
启动nginx服务: systemctl start nginx
其它: 查看配置文件有没有错误:nginx -t
重载服务:nginx -s reload
结束进程:pkill nginx
4.32/4.33 nginx虚拟主机
虚拟主机的概念: 从HTTP的相关概念理解为:一个web服务可以有多个站点,一个站点就是一个虚拟主机。 检测80端口通不通:telnet ip地址 80
查看防火墙规则:iptables -nvL
CentOS7自带firewalld服务,默认开启; 关闭防火墙:systemctl stop firewalld
将80端口加入正常访问规则:firewall-cmd --add-port=80/tcp --permanent
重载firewalld服务:firewall-cmd --reload
本地解析:vi /etc/hosts
为增加域名指向IP地址:IP地址 域名
例:192.168.142.131 www.111.com
为nginx服务设置默认虚拟主机: vi /etc/nginx/conf.d/*.conf
在监听端口后加入default_server
每次编辑完配置文件后都需要检测配置文件是否有错,然后再重载或重启服务。 默认虚拟主机可以实现泛解析,在配置文件中加入deny all;
可禁止默认虚拟主机。 设置本地域名解析:192.168.142.131 blog.riceyoung.com
编辑配置文件:
[root@rice01 conf.d]# cp default.conf blog.riceyoung.com.conf
// 拷贝 default.conf 并将文件名修改为 blog.riceyoung.com.conf
[root@rice01 conf.d]# vi blog.riceyoung.com.conf
// 设置 server_name 为 blog.riceyoung.com
[root@rice01 conf.d]# nginx -t
// 检测配置文件有无错误
[root@rice01 conf.d]# nginx -s reload
// 重载 nginx 服务
修改windows系统本地解析: 打开C:\Windows\System32\drivers\etc\hosts
,在最后一行加入IP地址 域名
; 此时在本地windows系统打开浏览器访问blog.riceyoung.com
正常访问。
4.34 安装wordpress
安装wordpress:
[root@rice01 ~]# mkdir -p /data/wwwroot/blog.riceyoung.com
// 创建目录
[root@rice01 ~]# cd /data/wwwroot/blog.riceyoung.com
[root@rice01 blog.riceyoung.com]# wget https://cn.wordpress.org/wordpress-5.0.3-zh_CN.tar.gz
[root@rice01 blog.riceyoung.com]# tar zxvf wordpress-5.0.3-zh_CN.tar.gz
[root@rice01 blog.riceyoung.com]# mv wordpress/* ./
// 将目录 wordpress 下的所有文件移动至当前目录下
[root@rice01 blog.riceyoung.com]# rm -rf wordpress wordpress-5.0.3-zh_CN.tar.gz
// 删除目录 wordpress 及 压缩包 wordpress-5.0.3-zh_CN.tar.gz
编辑nginx配置:
[root@rice01 ~]# vi /etc/nginx/conf.d/blog.riceyoung.com.conf
server {
listen 80;
server_name blog.riceyoung.com; // 定义域名
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /data/wwwroot/blog.riceyoung.com; // 定义路径
index index.html index.htm index.php; // 增加 index.php 索引
}
location ~ \.php$ {
root /data/wwwroot/blog.riceyoung.com; // 定义路径
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/blog.riceyoung.com$fastcgi_script_name;
// 定义 fastcgi_param SCRIPT_FILENAME
include fastcgi_params;
}
}
创建数据库:
[root@rice01 blog.riceyoung.com]# chown -R php-fpm .
// 为当前目录下的文件设置所属主,但在生产环境中,只给需要写入权限的文件设置属主
[root@rice01 blog.riceyoung.com]# mkpasswd -s 0 -l 16
// 生成随机密码,‘-s 0’ 为包含特殊字符数,‘-l 16’ 为密码长度为16个字符
[root@rice01 blog.riceyoung.com]# mysql -uroot -p111111
MariaDB [(none)]> create database blog;
// 创建库 blog
MariaDB [(none)]> grant all on blog.* to 'blog'@'127.0.0.1' identified by 'I3jpok8Ydzmiqomy';
// 创建用户 blog、数据库主机127.0.0.1、访问密码 I3jpok8Ydzmiqomy
MariaDB [(none)]> show databases;
// 查看有那些库
[root@rice01 blog.riceyoung.com]# mysql -ublog -pI3jpok8Ydzmiqomy -h127.0.0.1
MariaDB [blog]> show tables;
// 查看有那些表
MariaDB [blog]> use *(库名);
// 切换库
创建wp-config.php:
4.35 安装discuz
下载discuz:
[root@rice01 ~]# yum install -y git
[root@rice01 ~]# cd /usr/local/src/
[root@rice01 src]# git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git
// 克隆 discuz 到当前目录
[root@rice01 src]# cp -r DiscuzX/upload /data/wwwroot/bbs.riceyoung.com
// 拷贝目录 upload 至 /data/wwwroot/ 下并更名为 bbs.riceyoung.com
[root@rice01 src]# rm -rf DiscuzX
// 删除目录 DiscuzX
虚拟主机配置:
[root@rice01 src]# cd /etc/nginx/conf.d/
[root@rice01 conf.d]# cp blog.riceyoung.com.conf bbs.riceyoung.com.conf
[root@rice01 conf.d]# vi bbs.riceyoung.com.conf
server {
listen 80;
server_name bbs.riceyoung.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /data/wwwroot/bbs.riceyoung.com;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /data/wwwroot/bbs.riceyoung.com;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/bbs.riceyoung.com$fastcgi_script_name;
include fastcgi_params;
}
}
[root@rice01 conf.d]# nginx -t && nginx -s reload
安装discuz:
[root@rice01 conf.d]# cd /data/wwwroot/bbs.riceyoung.com
[root@rice01 bbs.riceyoung.com]# chown -R php-fpm config data uc_server/data uc_client/data
[root@rice01 bbs.riceyoung.com]# mysql -uroot -p111111
MariaDB [(none)]> create database bbs;
MariaDB [(none)]> grant all on bbs.* to 'bbs'@127.0.0.1 identified by 'oynqIbfK3yjak2ar';
[root@rice01 bbs.riceyoung.com]# mysql -ubbs -poynqIbfK3yjak2ar -h127.0.0.1
MariaDB [(none)]> use bbs;
MariaDB [bbs]> show databases;
创建论坛: 类似创建wordpress,设置数据库主机、用户名、密码、数据库名等信息进行创建。