网站首页 > 技术教程 正文
前情提要:昨天分享了怎么在Linux环境下安装并测试Nginx,今天就让我们一起上高速飙飙车
同样,上高速之前我们需要给我们昨天造的车改造一下引擎,要不怎么能干过别人的了,哈哈……
1、修改nginx.conf配置文件
(1)[root@stoneBoy home]# cd /usr/local/nginx/conf/
(2)[root@stoneBoy conf]# vi nginx.conf 然后进入编辑模式(按【i】),在http模块部分加入如下配置:
nginx.conf配置文件修改
重点是我圈出来的部分!!!文本如下:
...
upstream web1{
server 127.0.0.1:8081 weight=1 max_fails=2 fail_timeout=30s;
server 127.0.0.1:8082 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
location / {
#root html;
#index index.html index.htm;
index index.jsp index.html index.htm;
root /usr/local/nginx/html;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web1;
}
...
备注:a. weight=1:权重,nginx命中当前tomcat的概率,数值越大,命中率越高;
b. max_fails=2 心跳最大尝试次数,就是nginx服务器如果去ping 8081服务器,如果有两次都没ping通,它会默认该服务已挂,下次就不会再向它分发请求;
c. fail_timeout=30s 超时时间
(3)其实这样nginx就已经可以实现分发地效果了,为了能更好的区分,我用了两个示例项目,以下为后续操作步骤:
[root@stoneBoy usr]# cd tomcat7_8081/conf/ #进入你所配置tomcat的配置文件目录
[root@stoneBoy conf]# vi server.xml
server.xml配置文件修改
加入 <Context path="" docBase="testnginx1" reloadable="true" debug="0" privileged="true"></Context>,每个tomcat都要配置一下默认路径,否则会默认apache的主页
(4)测试 在浏览器中输入192.16.1.14(这是我服务器的ip,改成各位自己的就行).就可以得要你想要的了
tomcat_8081
tomcat_8082
猜你喜欢
- 2024-10-10 Nginx之进程间的通信机制(共享内存、原子操作)
- 2024-09-12 Linux下安装JDK和Nginx(linuxyum安装jdk1.8)
- 2024-09-12 脚本安装nginx(脚本安装了怎么运行)
- 2024-09-12 Linux安装Nginx(linux安装jdk)
- 2024-09-12 在linux系统上安装以及配置 nginx-1.20.1.tar.gz
- 2024-09-12 Nginx详细总结(建议收藏)(nginx详细讲解)
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)