nginx反向代理实现和分析
nginx反向代理实现和分析
一.安装
安装nginx
yum install nginx

二.配置
注:假设有两个配置
location /ibp/ {
proxy_pass http://dmx.xx.ha.yc/ibp/;
}
location /ibp/ {
proxy_pass http://dmx.xx.ha.yc/ibp;
}
第一个代理后是http://dmx.xx.ha.yc/ibp/manage/,第二个代理后是http://dmx.xx.ha.yc/ibpmanage/


Nginx主配置文件示例
[root@localhost nginx]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format proxy_log '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'Client Request URI: $request_uri '
'Proxy Target: $proxy_host$request_uri';
access_log /var/log/nginx/access.log proxy_log;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
}
}
在include /usr/share/nginx/modules/*.conf下设置负载均衡配置

验证负载均衡,访问http://10.1.1.115/ibp成功

三.分析
在服务器端抓包并下载
tcpdump -i ens835f3 dst port 80 -w capture.pcap

在本地工具打开可以看到访问目的地址是dmx.xx.ha.yc,源页面访问地址是http://10.1.1.115/ibp,因此也可以证明反向代理成功。


浙公网安备 33010602011771号