(总结)Nginx与Apache、Tomcat、Resin动静分离核心配置
来源:互联网 发布:ios 数组按长度切割 编辑:程序博客网 时间:2024/04/29 10:43
PS:近来有几个刚使用nginx的新童鞋老问我,nginx+fastcgi不够稳定,偶尔出现502错误,怎么解决?本人使用nginx也有3年多了,也认为php-fpm模块不够稳定,在访问量不大的时候没事,访问量增大时易出现502,当然这个还跟nginx的一些缓存设置和超时设置有关,设置不合理就易出现。php-fpm动态生成大型页面也没有优势,有时候会使php-cgi进程变成僵尸进程。据说php 5.4版本已自带php-fpm模块,稳定性是否有改进?太新还没用过,不评论。其实本人比较喜欢nginx跑静态和做负载反向代理,动态php还是交给apache处理比较稳定,jsp就交给tomcat、resin或jboss。nginx跑静态的能力是无与伦比的,是目前web服务器里最强的。nginx和apache、tomcat、resin的动静分离配置其实很简单,就几句配置,稳定性也非常好。
1、nginx和apache的动静分离配置:
把下面配置放到nginx配置文件相应的server { }里面,如果使用其他端口号,改一下就行:
#所有php的动态页面均交由apache处理
location ~ .(php)?$ {
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://127.0.0.1:88;
}
#所有静态文件由nginx直接读取不经过apache
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{ expires 15d; }
location ~ .*.(js|css)?$
{ expires 1h; }
如果之前设置了FastCGI的,把下面的配置注释掉:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ .php$ {
# root /var/www/html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# include fastcgi.conf;
#}
重启nginx就生效,如图所示,标头显示nginx,phpinfo里面显示是apache,说明动静分离生效。
2、nginx和tomcat、resin的动静分离配置:
同上,把下面配置放到nginx配置文件相应的server { }里面:
#所有jsp的页面均交由tomcat或resin处理
location ~ .(jsp|jspx|do)?$ {
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://127.0.0.1:8080;
}
#所有静态文件由nginx直接读取不经过resin
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{ expires 15d; }
location ~ .*.(js|css)?$
{ expires 1h; }
- (总结)Nginx与Apache、Tomcat、Resin动静分离核心配置
- (总结)Nginx与Apache、Tomcat、Resin动静分离核心配置
- Nginx与Apache、Tomcat、Resin动静分离核心配置-单主机
- Nginx与Apache、Tomcat、Resin动静分离的配置
- nginx,tomcat配置动静分离
- nginx tomcat 动静分离配置
- Apache与Tomcat动静分离(mod_jk)
- apache + tomcat动静分离配置
- Nginx + Tomcat 动静分离
- nginx+tomcat动静分离
- nginx +tomcat 动静分离
- Tomcat+nginx 动静分离
- nginx+tomcat 动静分离
- nginx动静分离配置
- Nginx 动静分离(代理Tomcat,Jetty)
- apache+nginx 实现动静分离
- apache+nginx 实现动静分离
- Nginx+Apache搭建动静分离
- Apache与Tomcat的3种连接方式分析
- mvc3 路由学习 自定义路由
- 解决Unable to read TLD "META-INF/tlds/struts-bean.tld" from JAR file
- iphone 第三天
- IOCP学习理解一
- (总结)Nginx与Apache、Tomcat、Resin动静分离核心配置
- iPhone 第四天
- Virgo Tomcat Server简析
- 全球企业专利实力排行榜:华为和清华大学在列
- 在ASP.NET高级中运用DataList使用存储过程实现分页
- Delphi的学习笔记八——内存操作函数
- C#异步分步调用
- MySQL带参数的存储过程小例子
- 电脑设置成护眼色