nginx安装
https://blog.youkuaiyun.com/weisong530624687/article/details/79743416
nginx的运行
进入sbin目录下执行./nginx
重新启动使用./nginx -s reload
nginx的使用
修改配置即可
进入conf目录下的nginx.conf文件
配置的是告诉nginx,访问哪个地址(可以一个和多个)
注意:
配置之后需要重启
nginx -s reload
1、配置一个地址
a、修改默认的页面(输入本虚拟机IP,会进入你告诉nginx需要跳转的服务地址http://192.168.91.128:9080,会显示tomcat的页面)
location / {//资源路径/
root html;
index index.html index.htm;
proxy_pass http://192.168.91.128:9080;//需要niginx跳转的服务器地址
}
b、不修改默认的页面可以使用(这样你就可以输入http://192.168.91.128/index访问http://192.168.91.128:9080/index
直接访问 http://192.168.91.128依然是nginx的默认html页面 )
location / {
root html;
index index.html
}
location /index {//资源路径/index
proxy_pass http://192.168.91.128:9080;//需要跳转的服务器地址
}
2、配置多个地址
配置负载均衡
upstream ss{
server 192.189.11.22:8080;
server 192.189.11.22:9080;
server 192.189.11.22:9081;
}
location / {
root html;
index index.html index.htm;
proxy_pass http://ss;//需要跳转的服务器地址
}
注意:1、需要注意写upstream ss时,中间是空格
2、位置要写对不然会报错
这样就可以