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. PostgreSQL连接Python

    安装 PostgreSQL可以用Python psycopg2模块集成. sycopg2是Python编程语言的PostgreSQL数据库的适配器. 其程序代码少,速度快,稳定.不需要单独安装这个模块 ...

  2. 003. 连接access数据库代码

    1. 前端aspx中的代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="De ...

  3. 螺旋矩阵 noip2014普及组

    本题可以直接模拟填数字,也可以直接计算结果. 代码一:(这个代码,缺陷在于数组太大,浪费内存啊.另外,循环次数也不少.总之,时间空间的消耗都不小.) /*======================= ...

  4. 【转】第4篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:委托回调方法分析

    作者: 牛A与牛C之间 时间: 2013-11-18 分类: 技术文章 | 暂无评论 | 编辑文章 主页 » 技术文章 » 第4篇:Xilium CefGlue 关于 CLR Object 与 JS ...

  5. 导入安卓项目的时候,发生错误:Cause: peer not authenticated

    导入安卓项目时出现Cause: peer not authenticated. 在网上搜了解决方案,都没有凑效.后来干脆插上手机直接debug安装,竟然成功了,成功了,成功了!!!! 然后再次buil ...

  6. python数据类型之int用法

    1.查看整型的用法 CODE:print(dir(int))['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', ...

  7. SQL常见的可优化点

    # 索引相关 # ################################################### 1. 查询(或更新,删除,可以转换为查询)没有用到索引 这是最基础的步骤,需要 ...

  8. oracle定时运行 存储过程

    /* 查询: select job,broken,what,interval,t.* from user_jobs t; job job的唯一标识,自动生成的 broken 是否处于运行状态,N;运行 ...

  9. nginx+tomcat+redis的集群+session共享

    nginx+tomcat+redis的集群+session共享 环境准备 1.tomcat版本:tomcat7 tomcat下载及安装,目前很多好的资源和步骤,此处省略. 2.jdk版本:jdk1.7 ...

  10. Protocol Buffer基本介绍

    转自:http://www.cnblogs.com/stephen-liu74/archive/2013/01/02/2841485.html 该系列Blog的内容主体主要源自于Protocol Bu ...