CentOS 7.4 Tengine安装配置详解(六)

前端之家收集整理的这篇文章主要介绍了CentOS 7.4 Tengine安装配置详解(六)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

十五、反向代理:

1、演示环境:

IP

操作系统

节点

角色

192.168.1.222

CentOS 7.4

node1

Tengine服务器

192.168.1.144

CentOS 6.9

node2

Apache服务器


2、node2安装Apache服务,并创建测试页:

# yum -y install httpd

# mkdir -pv /var/www/html/bbs

# echo "<h3>httpd on node2</h3>" > /var/www/html/index.html

# echo "<h3>bbs on node2</h3>" > /var/www/html/bbs/index.html

# service httpd start

# ss -tunlp | grep :80


3、node1访问node2# curl http://192.168.1.144

4、修改本地Windows 10系统的hosts文件C:\Windows\System32\drivers\etc\hosts,末尾新增代码192.168.1.222 node1.qiuyue.com,访问http://node1.qiuyue.com

5、将所有请求都反代至http://192.168.1.144

(1)修改node1配置文件Nginx.conf

server {

listen 80;

server_name node1.qiuyue.com;

location / {

proxy_pass http://192.168.1.144;

index index.html index.html;

}

}

(2)重载服务:# Nginx -t # Nginx -s reload

(3)本地Windows 10访问http://node1.qiuyue.com

6、/bbs的请求反代至http://192.168.1.144/bbs

root html;

}

location /bbs {

proxy_pass http://192.168.1.144/bbs;

http://node1.qiuyue.comhttp://node1.qiuyue.com/bbs

7、/forum的请求反代至 location /forum {

http://node1.qiuyue.com/forum

8、将以jpgpng或者gif结尾的请求反代至 location ~* \.(jpg|png|gif)$ {

proxy_pass http://192.168.1.144;

(3)node2创建测试目录:# mkdir -pv /var/www/html/images

(4)node2上传测试图片1.jpg/var/www/html/images

(5)本地http://node1.qiuyue.com/images/1.jpg

9、定义访问日志:

(1)node2的默认访问日志:# tail -3 /var/log/httpd/access_log

备注:并不是记录访问的本地Windows 10IP,而是node1IP

(2)修改proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

}

(2)重载服务:# Nginx -t # Nginx -s reload

(3)修改node2配置文件httpd.conf

确认访问日志使用的是CustomLog logs/access_log combined

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined修改

LogFormat "%{X-Real-IP}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

# service httpd restart

(4)本地http://node1.qiuyue.com/images/1.jpghttp://node1.qiuyue.com

(5)node2修改后的访问日志:# tail -5 /var/log/httpd/access_log

IP

备注:已记录访问的本地IP,而不是IP

原文链接:https://www.f2er.com/centos/374223.html

猜你在找的CentOS相关文章