1.配置配置阿里云epel源和base源
[root@localhost ~]$ wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]$ wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]$ ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo
CentOS-Debuginfo.repo CentOS-Sources.repo epel.repo
2.安装nginx的rpm包
wget http://nginx.org/download/nginx-1.23.3.tar.gz
#解压
tar -zxvf nginx-1.23.3.tar.gz
#安装依赖
yum -y install gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
#初始化
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
make
make install
3.启动nginx
[root@localhost /]# whereis nginx
nginx: /usr/local/nginx
[root@localhost /]# ./usr/local/nginx/sbin/nginx
[root@localhost /]# ps -ef | grep nginx
root 7184 1 0 10:11 ? 00:00:00 nginx: master process ./usr/local/nginx/sbin/nginx
nobody 7185 7184 0 10:11 ? 00:00:00 nginx: worker process
root 7187 1773 0 10:11 pts/0 00:00:00 grep --color=auto nginx
4.关闭防火墙
[root@localhost /]# systemctl stop firewalld.service
[root@localhost /]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost /]# vim /etc/selinux/config
[root@localhost /]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
5.测试是否访问成功
6.准备好两台配置好的web服务器
192.168.40配置的网站:
192.168.0.50配置的网站:
7.配置反向代理
修改配置文件:
#重启服务
[root@localhost /]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost /]# /usr/local/nginx/sbin/nginx -s reload
8.测试结果
访问反向代理服务器可以到达两个web服务器