什么是反向代理?
客户端本来可以直接通过 HTTP 协议访问某网站应用服务器,如果网站管理员在中间加上一个 Nginx,客户端请求 Nginx,Nginx 请求应用服务器,然后将结果返回给客户端,此时 Nginx 就是反向代理服务器。
反向代理配置
[root@centos7 ~]# vim /usr/local/nginx/conf/nginx.conf
upstream test {
server 192.168.100.2:80;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://test;
root html;
index index.html index.htm;
}
}
[root@centos7 ~]# /usr/local/nginx/sbin/nginx -s reload
- 应用服务器配置
[root@lnmp1 ~]# yum -y install httpd
[root@lnmp1 ~]# echo "test successful .." > /var/www/html/index.html
[root@lnmp1 ~]# systemctl start httpd
测试
- 访问 Nginx 服务器