Nginx
Posted 馳騁衿琾
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx相关的知识,希望对你有一定的参考价值。
1.http服务器
2.虚拟主机
3.反向代理,负载均衡
安装nginx
配置虚拟主机:
/usr/local/nginx/conf/nginx.conf
一个server就是一个虚拟主机
1.通过端口访问
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } }
server { listen 81; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } }
2.共用80端口,通过域名访问
server { listen 80; server_name www.jd.com; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } } server { listen 80; server_name www.taobao.com; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } }
反向代理:
启动两个tomcat:
upstream tomcat1 { server 192.168.25.148:8080; } server { listen 80; server_name www.sina.com.cn; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://tomcat1; index index.html index.htm; } } upstream tomcat2 { server 192.168.25.148:8081; } server { listen 80; server_name www.sohu.com; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://tomcat2; index index.html index.htm; } }
负载均衡:
再启动一个tomcat,修改端口为8082,
访问www.sohu.com会轮询访问 weight=2的请求次数越多
upstream tomcat2 { server 192.168.25.148:8081; server 192.168.25.148:8082 weight=2;
} server { listen 80; server_name www.sohu.com; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://tomcat2; index index.html index.htm; } }
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
|
location / {
root html;
index index.html index.htm;
}
}
以上是关于Nginx的主要内容,如果未能解决你的问题,请参考以下文章