nginx 均衡负载配置
nginx详细配置介绍:
参考资料:http://blog.csdn.net/xmtblog/article/details/42295181
配置实例:
// nginx服务器虚拟为代理服务器和web服务器
#user nobody;
worker_processes 4 ; //一般和CPU核相等 #pid logs/nginx.pid; events { worker_connections 1024 ; //最大连接数
} http {
include mime.types; //服务器能识别的文件类型
default_type application/octet-stream;
sendfile on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; upstream myServer{ //设置服务器集群 server 192.168.1.251:80 weight=1; //设置服务器,和访问权重
server 192.168.1.252:8080 weight=1;
} server { //设置反向代理服务器,监听端口为80
listen 80;
server_name www.myproxy.com ; #charset koi8-r; #access_log logs/host.access.log main; root /phpstudy/wwww;
location /{ # index index.html index.htm index.php
proxy_pass http://myServer; //指定反向代理的服务器集群
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ { //rewrite URL 正则表达 若url地址以.php结尾,则执行下面代码
proxy_pass http://myServer;
# proxy_set_header X_Real_IP $remote_addr;
# proxy_set_header X-Host $host; }
} server{ //设置web服务器,监听端口为8080,
listen 8080;
server_name www.centos2.com;
root /phpstudy/www;
location / { index index.php index.htm index.html ;
}
#error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} location ~ \.php(.*)$ { //若遇到以php结尾的文件就交个9000端口的 fastcgi执行php代码
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
} include /phpstudy/server/nginx/conf/vhosts/*.conf;
}
注意:http下的server模块是设置虚拟服务器的,不同于upstream下的server模块,另外作为web服务器要对php文件执行,必须要指定提交给fastcgi解析,
否则浏览器无法识别将提示下午。
nginx 均衡负载配置的更多相关文章
- Nginx均衡负载配置
前言:Nginx也是一种服务器,反向代理服务器.单一tomcat能承受的并发访问量在150-200之间,还是在比较理想的情况下,当并发量超出这个范围,便需要Nginx实现多个tomcat的均衡负载,但 ...
- nginx均衡负载
一直在担心session 问题,结果试了2个web 论坛,discuz 和phpbb ,前面用nginx 均衡负载,后端是apache httpd +php ,mysql 用同一个,修改一下confi ...
- Nginx均衡负载(IP_HASH)未生效
由于公司业务的发展,单台服务器已经无法满足并发和用户的需求,所以只能通过水平拓展的方式加机器来解决,线上采用的是Nginx+Tomcat集群的方式来解决.由于当前业务量不是很大,而且由于之前代码的问题 ...
- Tomcat学习总结(8)——Tomcat+Nginx集群解决均衡负载及生产环境热部署
近日,为解决生产环境热部署问题,决定在服务器中增加一个tomcat组成集群,利用集群解决热部署问题. 这样既能解决高并发瓶颈问题,又能解决热部署(不影响用户使用的情况下平滑更新生产服务器)问题. 因为 ...
- 配置nginx的负载均衡
1.1 什么是负载均衡 负载均衡 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用性. 负载均衡,英文名称 ...
- nginx作为负载均衡服务器——测试
i. 需求 nginx作为负载均衡服务器,用户请求先到达nginx,再由nginx根据负载配置将请求转发至 tomcat服务器. nginx负载均衡服务器:192.168.101.3 tomcat1服 ...
- Nginx总结(六)nginx实现负载均衡
前面讲了如何配置Nginx虚拟主机,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要 ...
- Nginx简单介绍以及linux下使用Nginx进行负载均衡的搭建
1.Nginx简介 Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev所开发,官方测试nginx能够支支撑5 ...
- nginx反向代理配置两个不同服务器
1.什么是反向代理通常的代理服务器,只用于代理内部网络对Internet的连接请求,客户机必须指定代理服务器,并将本来要直接发送到Web服务器上的http请求发送到代理服务器中由代理服务器向Inter ...
随机推荐
- Axure折叠与展开效果的实现
http://www.masterchat.cn/article/20120501/217.html 视频教程 项目效果 点击表头,内容会展开或者收缩. 第一步,用矩形工具分别建立如下效果的图形 2, ...
- shell之数组
1.从数组的下标分为索引数组.关联数组 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 /* 索引数组,即通常情况下所说的数组 */ var ary1 = [1,3,5, ...
- 【转】PHP简单拦截器的实现
最近在看Yii的源代码,收获了不少,这里就是从中得到的启发,而写的一个简单拦截器的实现下面看例子: <?phpclass A{ private $_e = array(); p ...
- java通过ftp和sftp上传war包上传到Linux服务器实现自动重启tomcat的脚本代码
ar包自动上传Linux并且自动重启tomcat 用的是jdk1.7出的文件监控 支持ftp和sftp,支持多服务器负载等 配置好config 非maven项目导入直接使用 #\u76D1\u542C ...
- mysql log
mysql binlog3种格式,row,mixed,statement. 解析工作 mysqlbinlog --base64-output=DECODE-ROWS -v mysql-bin.0001 ...
- 01TCP/IP基础
ISO/OSI参考模型: OSI(open system interconnection)开放系统互联模型是由ISO(International Organization for Standardiz ...
- 什么是SQLCLR与使用
原帖地址:http://www.cnblogs.com/hsrzyn/archive/2013/05/28/1976555.html 什么是SQLCLR SQL CLR (SQL Common Lan ...
- item30,最小的k个数
剑指offer给出两类方法: 1,借助快排的思想,需要修改输入数组的元素,时间复杂度O(n) 2,借助STL中set或者multiset,因为它们的底层数据结构是红黑树实现的,插入数据时间复杂度为O( ...
- 程序包com.sun.image.codec.jpeg不存在 问题的完美解决
原文地址:http://my.oschina.net/zb0423/blog/86507 在使用Hudson进行打包的过程中,因为我们使用了一个pdf文件产生缩略图的功能,倒置添加的源码文件在mave ...
- 杀死future处理的阻塞线程
public class Test{ public static void main(String[] args){ ExecutorService pool = Executors.newFixed ...