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. Windows动态链接库DLL

    1.什么是DLLDLL,即动态链接库,是包含若干个函数的库文件,可供其他程序运行时调用. 2.DLL的优缺点优点:代码重用,可供多个程序同时调用 缺点:易发生版本冲突当新版本的动态链接库不兼容旧版本时 ...

  3. 009. C#中的WebBrowser控件的属性、方法及操作演示代码(转)

    本文转自 http://www.open-open.com/code/view/1430559996802 0.常用方法 Navigate(string urlString):浏览urlString表 ...

  4. API、ABI区别

    http://blog.csdn.net/xinghun_4/article/details/7905298 应用程序二进制接口(ABI-Application Binary Interface)定义 ...

  5. shell之脚本练习

    脚本需求集合贴-自主开发的 对频繁执行的任务有编写脚本的价值 对单次执行的任务就用笨的,简单的办法 1.对asterisk写一个脚本 查日志 输入日期--能够输出对应日期的日志 输入多个条件--能够输 ...

  6. oracle的高可用与负载均衡

    浏览了一下Oracle官方的网页以及非官方的ppt,简单了解了一下Oracle提供的高可用方案.1. RACRAC,  Real Application Clusters多个Oracle服务器组成一个 ...

  7. [mysql] linux 下mysql 5.7.12 安装

    1.下载mysql wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar ...

  8. MySQL瘦身

    解压mysql-x.y.z-win32|64.zip 删除不用的目录:保留bin.data.share三个文件夹 删除bin里的多余文件:保留mysqld.exe.mysqladmin.exe (如果 ...

  9. routeros的配置资料

    http://blog.csdn.net/boliang319/article/details/41800261 http://blog.csdn.net/boliang319/article/det ...

  10. [dts]DTS实例分析

    此篇源文件arch/arm/boot/dts/imx6sx.dtsi 1. dts和dtsi完成的功能 以下是两段较为常见的dtsi和dts代码 uart5: serial@021f4000 { co ...