1.nginx代理
1.1正向代理与反向代理的区别
服务的对象不一样,正向代理的服务对象为客户端,反向代理为服务端服务(用于企业集群架构,后端有多个web节点组成的集群,然后接入代理,由代理统一调度)
1.2代理模块
反向代理模式 | Nginx反向代理模块 | 作用于 |
---|---|---|
http、websocket、https | ngx_http_proxy_module | java,http,https |
fastcgi | ngx_http_fastcgi_module | php |
uwsgi | ngx_http_uwsgi_module | python |
grpc | ngx_http_v2_module | go |
1.3 反向代理简单实例
web服务器(10.0.0.7):
yum install nginx -y
mkdir -p /code/web
vim /etc/nginx/conf.d/web.com
-----------------/etc/nginx/conf.d/web.com---------------------------
server {
listen 8080;
server_name web.com;
root /code/web;
location / {
index index.html;
}
}
-----------------/etc/nginx/conf.d/web.com结束------------------------
nginx -t
systemctl reload nginx
lb服务器(10.0.0.5):
gzip /etc/nginx/conf.d/default.conf #打包默认网页,防止截获
vim /etc/nginx/conf.d/proxy_web.conf
-----------------/etc/nginx/conf.d/proxy_web.conf---------------------
server {
listen 80;
location / {
proxy_pass http://10.0.0.7:8080;
}
}
-----------------/etc/nginx/conf.d/proxy_web.conf结束------------------
nginx -t
systemctl start nginx
systemctl enable nginx
Windows的c:\windows\system32\drives\etc\hosts中添加:
10.0.0.5 web.com
在windows浏览器中输入域名web.com即可访问。