Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。
nigx有两大功能,反向代理和负载均衡,
首先我们先说反向代理和正向代理的区别:
什么是正向代理,举个例子,当我们想访问外国的网站的时候,我们的请求不能直接到外国的服务器上,应该是先到国内的
某台服务器,这个服务器再去访问外国的服务器麻将结果再返回给我们
反向代理现在市场上应用比较广泛,现在主流的架构,分布式,我们的服务不会再一个服务器上,而是多个,我们将我们的请求,
通过反向代理的形式,去请求到每一个服务上
反向代理的使用:
找到nigx的的nigx.conf文件,在文件中加上
upstream tomcatserver{
server 192.168.100.10:8080;
server 192.168.100.10:8081;
}
server{
linsten 80;
server_name localhost;
#指向nginx默认首页
location / {
root html;
index index.shtml index.htm;
}
location /replay/{
alias /文件路径 或者 root /文件路径
index index.html;
}
#代理
location ^~/proxyPath{
#访问127.0.0.1:80/proxyPath/path
#会被代理到127.0.0.1:8080/path
proxy_pass http://127.0.0.1:8888;
}
}
注意在配置路径的时候root关键字与alias
当配置的是
location /replay/{
alias /root/project
index index.html;
}
访问/127.0.0.1:80/replay/index会被指向/root/project/index
当配置的
location /replay/{
root /root/project;
index index.html;
}
访问/127.0.0.1:80/replay/index会被指向/root/project/replay/index
个人学习 如果写的不过的大神留言指点下