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 均衡负载配置的更多相关文章

  1. Nginx均衡负载配置

    前言:Nginx也是一种服务器,反向代理服务器.单一tomcat能承受的并发访问量在150-200之间,还是在比较理想的情况下,当并发量超出这个范围,便需要Nginx实现多个tomcat的均衡负载,但 ...

  2. nginx均衡负载

    一直在担心session 问题,结果试了2个web 论坛,discuz 和phpbb ,前面用nginx 均衡负载,后端是apache httpd +php ,mysql 用同一个,修改一下confi ...

  3. Nginx均衡负载(IP_HASH)未生效

    由于公司业务的发展,单台服务器已经无法满足并发和用户的需求,所以只能通过水平拓展的方式加机器来解决,线上采用的是Nginx+Tomcat集群的方式来解决.由于当前业务量不是很大,而且由于之前代码的问题 ...

  4. Tomcat学习总结(8)——Tomcat+Nginx集群解决均衡负载及生产环境热部署

    近日,为解决生产环境热部署问题,决定在服务器中增加一个tomcat组成集群,利用集群解决热部署问题. 这样既能解决高并发瓶颈问题,又能解决热部署(不影响用户使用的情况下平滑更新生产服务器)问题. 因为 ...

  5. 配置nginx的负载均衡

    1.1   什么是负载均衡 负载均衡 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用性. 负载均衡,英文名称 ...

  6. nginx作为负载均衡服务器——测试

    i. 需求 nginx作为负载均衡服务器,用户请求先到达nginx,再由nginx根据负载配置将请求转发至 tomcat服务器. nginx负载均衡服务器:192.168.101.3 tomcat1服 ...

  7. Nginx总结(六)nginx实现负载均衡

    前面讲了如何配置Nginx虚拟主机,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要 ...

  8. Nginx简单介绍以及linux下使用Nginx进行负载均衡的搭建

    1.Nginx简介 Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev所开发,官方测试nginx能够支支撑5 ...

  9. nginx反向代理配置两个不同服务器

    1.什么是反向代理通常的代理服务器,只用于代理内部网络对Internet的连接请求,客户机必须指定代理服务器,并将本来要直接发送到Web服务器上的http请求发送到代理服务器中由代理服务器向Inter ...

随机推荐

  1. http,ftp

    HTTP和FTP的区别 标签: ftpFTPhttpHttpHTTP 2012-12-13 19:51 10544人阅读 评论(1) 收藏 举报  分类: 网络(2)    目录(?)[+]   今天 ...

  2. Advancing The Realtime Web With RethinkDB

    RethinkDB is an open-source distributed database built to store JSON and scale with very little effo ...

  3. Knockout.js, Asp.Net MVC and Bootstrap 前端设计

    原文地址:http://ddmvc4.codeplex.com/ 原文名称:Design and Develop a website using ASP.NET MVC 4, EF, Knockout ...

  4. Storyboard里面的几种Segue区别及视图的切换:push,modal,popover,replace和custom

    一.视图切换类型介绍 在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,segue的类型是不同的. 在iphone中,segue有:push,modal,和cus ...

  5. webstorm修改文件,webpack-dev-server不自动编译刷新的解决办法

    webstorm设置中,"Settings"--"Appearance & Behavior"--"System Settings" ...

  6. oracle定时任务JOB

    在jobs上点新建  what值:statisticsToDay;  这个是存储过程的名字间隔:sysdate+1/24   表示每个小时运行一次          1:每分钟执行 Interval ...

  7. get跟post编码--转

    1.Get是用来从服务器上获得数据(没有请求体),而Post是用来向服务器上传递数据(包含请求体). 2.Get将表单中数据的按照variable=value的形式,添加到action(服务)所指向的 ...

  8. [mysql] MariaDB 10.0.10 GTID复制

    一:概念理解:    1.TID:Transaction ID,即Mysql服务器的事务ID号. 2.GTID:Global Transaction ID,全局事务ID,在整个主从复制架构中任何两个事 ...

  9. js/jquery 操作document对象

    一.获取对象 //js获取的是dom对象,jquery获取的是jquery对象 //jquery对象可以输出dom对象,索引方式输出dom对象,eq()[]方式输出dom对象;eq()输出jquery ...

  10. git tag知多少

    这个命令,其实很有用,类似clearcase中的label,就是给一个版本设置一个标记(标签),方便后期查找特定的版本. tag和commit的sha1那串字符串的关系,不是很大,但是还是要说一下的. ...