赞
踩
# yum install -y gcc-c++
# yum install -y pcre pcre-devel
# yum install -y zlib zlib-devel
# yum install -y openssl openssl-devel
链接:https://pan.baidu.com/s/1qOyZXCHOIHyWobdyz3srVg?pwd=6666
提取码:6666
放入usr>soft中
# mkdir /usr/soft/nginx
# tar -zxvf nginx-1.18.0.tar.gz
# ./configure --prefix=/usr/soft/nginx
# make && make install
配置环境变量
# vi /etc/profile
然后刷新配置
# source /etc/profile
# sbin/nginx 启动nginx
# sbin/nginx -s stop 关闭nginx
# sbin/nginx -s reload 重新加载nginx配置
# ip addr 得到虚拟机ip
虚拟机ip:80,可在浏览器上访问nginx
# cd /usr/soft/nginx/conf 进入此目录
server {
listen 81;
server_name localhost;
location / {
root main;
index main.html;
}
}
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!Main</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
注意: 你修改了nginx配置文件,必须重新加载配置文件
# nginx -s reload
正向代理:
拿借钱打个比方,A想向C借钱,但是C不认识A,所以C不借给他,然后A就通过B向C借钱,B认识C,B借到钱之后再转交给A,在这个过程中B就扮演了一个正向代理的角色,这个过程中,真正借钱的人是谁,C是不知道的~
我们常说的代理也就是指正向代理,正向代理的过程,它隐藏了真实的请求客户端,服务端不知道真实的客户端是谁,客户端请求的服务都被代理服务器代替来请求.
反向代理:
还用借钱的例子,A想向C借钱,然后C借给他了,但是实际上这个钱可能时C向B借的,至于钱到底是谁的,A是不知道的
这里的C扮演着一个反向代理的角色,客户不知道真正提供服务的人是谁。
反向代理隐藏了真实的服务端,对于客户来说不知道访问的是哪台服务器。
准备
链接:https://pan.baidu.com/s/1-T1oUU8tDA_Bf14d2Kc7sA?pwd=6666
提取码:6666
配置nginx来代理上面springboot真实项目服务。
server {
listen 82;
server_name localhost;
location / {
# http://被代理的服务器IP和Port端口号
proxy_pass http://192.168.121.251:8080;
}
}
# ngnix -s reload
浏览器访问nginx
权重策略:合适服务器的配置不同,被访问的频率不同。
注意:修改完配置文件之后不要忘记重启服务.
ip_hash:根据客户端的ip分配相应真实服务器。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。