- 基础环境配置(1)配置静态IP地址
重启网络:systemctl restart network
(2)改主机名
(3)修改/etc/resolv.conf(允许外网访问)
(4)关闭防火墙:systemctl stop firewalld
(5)关闭selinux:setenforce 0
开机不启动 /etc/selinux/config
2.配置nginx软件的yum源
(1)下载wget
(2)删除本地网络源
(3)安装阿里云网络镜像
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
(4)打开CentOS-Base.Repo文件,将所有的http改为https,gpgcheck=1改为gpgcheck=0
(5)配置nginx软件yum源
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
(6)查看是否有nginx源
(7)下载nginx
(8)启动
systemctl start nginx
3.配置Nginx开启反向代理访问
vi /etc/nginx/conf.d/default.conf
vi /etc/nginx/conf.d/default.conf
server {
…
location / {
proxy_pass http://backend;
proxy_redirect default;
#设置代理
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
4.配置反向代理的主机是谁
vi /etc/nginx/nginx.conf
http {
…
Upstream backend {
Server 192.168.100.102:80; apache1主机IP
Server 192.168.100.103:80; apache2 主机IP
}
}
重启服务systemctl restart nginx
5.访问验证输入nginxIP
6.到Apache上查看日志
Vi /var/log/httpd/access_log
Apache1
Apache2