- virtualbox安装centos
- 宿主机wifi联网的情况下,centos的网路配置:ip addr命令输出联网信息,获得当前centos系统IP地址
- xshell操作centos
Apache
- 检查是否已经安装
rpm -qa httpd
- 安装apache
yum install httpd -y
- 开启httpd服务并开机启动
systemctl start httpd systemctl enable httpd #关闭httpd服务 #systemctl stop httpd
-
开启防火墙
#开启防火墙 systemctl start firewalld #打开80端口 firewall-cmd --zone=public --add-port=80/tcp --permanent #重启防火墙 firewall-cmd --reload #查询是否开启 firewall-cmd --list-ports #外网访问成功 #关闭防火墙,正式服务器请勿进行此操作 #systemctl stop firewalld #systemctl disable firewalld
-
关闭Selinux
#永久关闭 [root@localhost ~]# vim /etc/selinux/config SELINUX=disabled SELINUXTYPE=targeted #临时关闭 [root@localhost ~]# setenforce 0
-
默认文件存放路径:/var/www/html
-
配置文件路径:/etc/httpd/conf/httpd.conf
-
默认端口号:listen: 80,修改默认端口号记得打开端口
-
多端口配置虚拟主机
-
添加监听端口
[root@localhost conf.d]# vim /etc/httpd/conf/httpd.conf #添加行 Listen 8070 Listen 8080 Listen 8090
-
创建配置文件
[root@localhost ~]# cd /etc/httpd/conf.d/ [root@localhost conf.d]# vim virtual.conf <VirtualHost 192.168.56.102:8070> ServerName a.com DocumentRoot "/var/www/70/" </VirtualHost> <VirtualHost 192.168.56.102:8080> ServerName b.com DocumentRoot "/var/www/80/" </VirtualHost> <VirtualHost 192.168.56.102:8090> ServerName c.com DocumentRoot "/var/www/90/" </VirtualHost>
-
创建对应测试文件
-
重启服务,并执行访问
[root@localhost conf.d]# systemctl restart httpd
-
- 编译方式安装
- 安装依赖库
#gcc,用于编译 [root@localhost home]# yum -y install gcc #pcre、pcre-devel #正则,压缩、解压,ssl [root@localhost home]# yum install -y pcre pcre-devel [root@localhost home]# yum install -y zlib zlib-devel [root@localhost home]# yum install -y openssl openssl-devel
- home目录下载解压
[root@localhost home]# wget https://nginx.org/download/nginx-1.20.1.tar.gz [root@localhost home]# tar -zxvf nginx-1.20.1.tar.gz [root@localhost home]# cd nginx-1.20.1 [root@localhost home]# ./configure [root@localhost home]# make [root@localhost home]# make install #成功安装至/usr/local/nginx目录
- 启动服务
[root@localhost /]# cd /usr/local/nginx/sbin/ [root@localhost sbin]# ./nginx #检查是否启动 [root@localhost sbin]# ps -ef | grep nginx #cd /usr/local/nginx/sbin/ -- nginx目录 #./nginx -- 启动服务 #./nginx -s stop -- 停止服务 #./nginx -s quit -- 停止服务 #./nginx -s reload -- 重新加载服务 #ps aux|grep nginx -- 查询进程
- 访问页面
- 配置多个worker子进程
[root@localhost /]# cd /usr/local/nginx/ [root@localhost /]# vim /conf/nginx.conf #修改该行 worker_processes 1;
Nginx反向代理负载均衡
- 现实中同一台服务器实现反向代理是没有意义的,该负载多少还是负载多少;
PHP
MYSQL