?反向代理的作用
1、解決網(wǎng)站服務器對外可見的問題、私密性、安全性
2、路由功能:根據(jù)用戶請求的URI調(diào)度到對應功能的節(jié)點處理請求
3、負載均衡:將用戶的請求,通過調(diào)度算法挑選一臺合適的節(jié)點處理請求
4、動靜分離:根據(jù)用戶請求的URI進行區(qū)分,將動態(tài)資源調(diào)度到應用服務器處理,將靜態(tài)資源調(diào)度到靜態(tài)資源服務器處理
5、數(shù)據(jù)緩存:加速網(wǎng)站的訪問速度,減輕web服務器的負擔。如果用戶請求的內(nèi)容在緩存中,可以直接在代理服務器中獲取,加速用戶的訪問速度
web-01 | 192.168.200.120 |
web-02 | 192.168.200.121 |
web-01安裝、配置
cat > /etc/yum.repos.d/nginx.repo << OK
[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
module_hotfixes=true
OK
[root@nginx ~]# yum -y install nginx
[root@nginx ~]# cd /etc/nginx/conf.d/
[root@nginx conf.d]# mv default.conf{,.bak}
[root@nginx conf.d]# vim proxy_web.conf
server {
listen 80;
server_name www.test.org;
location / {
proxy_pass http://192.168.200.121:80;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[root@nginx ~]# sed -i '/^user/c user www;' /etc/nginx/nginx.conf
[root@nginx ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx ~]# systemctl enable nginx
[root@nginx ~]# systemctl start nginx
[root@nginx ~]# ps -ef | grep -v "grep" | grep nginx
root 2282 1 0 13:04 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
www 2283 2282 0 13:04 ? 00:00:00 nginx: worker process
web-02安裝、配置
cat > /etc/yum.repos.d/nginx.repo << OK
[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
module_hotfixes=true
OK
[root@nginx ~]# yum -y install nginx
[root@nginx ~]# cd /etc/nginx/conf.d/
[root@nginx conf.d]# mv default.conf{,.bak}
[root@nginx conf.d]# vim web01-test.conf
server {
listen 80;
server_name www.test.org;
root /code/web01;
location / {
index index.html;
}
}
[root@nginx conf.d]# mkdir -p /code/web01
[root@nginx conf.d]# echo "test-web01" >> /code/web01/index.html
[root@nginx conf.d]# chown -R www.www /code/
[root@nginx conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx conf.d]# systemctl enable nginx.service
[root@nginx conf.d]# systemctl start nginx.service
訪問測試、查看web-02日志
[root@nginx conf.d]# tailf /var/log/nginx/access.log
192.168.200.120 - - [19/Jun/2023:13:12:12 +0800] "GET / HTTP/1.0" 200 11 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0" "192.168.200.10"
使用wireshark抓包查看詳細過程
?文章來源地址http://www.zghlxwxcb.cn/news/detail-648613.html文章來源:http://www.zghlxwxcb.cn/news/detail-648613.html
?
到了這里,關(guān)于Nginx-反向代理(配置教程)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!