<article class="baidu_pl"> <div id="article_content" class="article_content clearfix csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post"> <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-f57960eb32.css"> <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-f57960eb32.css"> <div class="htmledit_views" id="content_views">php
<p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> nginx处理静态html页面的能力至关强悍,由于nginx采用了比select模型更拽的epoll ,因此若网站内容不是常常变更(大量的html页面),又须要同时支持其余诸如php、jsp的cgi脚本的,能够考虑使用nginx代替依然在使用select模型的apache(httpd);固然通过长期跟踪发现nginx的fastcgi(php-fpm)运行php会时不时的出现502的错误,并且彷佛尚未办法完全根除;因此不考虑超大流量的状况下配置php-fpm的方式让nginx支持php是个不错的选择,固然你也能够采用nginx的代理模块,来代理apache处理php,这块网络上已经有不少资料了,再也不赘述~本文主要针对同一80端口下的nginx同时支持php、jsp;因本人对jsp了解很少,错误之处还请包涵。</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> nginx做为一款新秀服务器软件,对于fastcgi方式支持php的相关资料已经不少了,随便搜索一下就能够找到许多,这里就再也不介绍nginx支持php的配置了,若是须要了解这方面的知识,能够参考本人的另一篇文章:</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> 文章名:<span style="line-height:1.5;">《CentOS6.3下编译安装配置nginx1.2.3+php5.3.16+mysql5.5.27+memcached1.4.5 》</span></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> 地址:<a href="http://blog.jjonline.cn/linux/centos6_3_nginx1_2_3_mysql5_5_27.html" rel="nofollow" style="color:rgb(0,162,202);text-decoration:none;" target="_blank">http://blog.jjonline.cn/linux/centos6_3_nginx1_2_3_mysql5_5_27.html</a> </p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> Ps:nginx php mysql版本的不一样配置原理相似,如有问题,能够给我留言,时间容许的状况下本人能够协助您排查~</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> ==============</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> <strong>tomcat6安装运行</strong></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> centos下安装支持jsp的tomcat服务器至关简单,一条yum命令所有搞定,固然你也能够参照网络上已有的代码编译模式或者rpm包安装模式安装,本文再也不介绍。</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> tomcat安装(tomcat6版本):</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> -----------------------</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> shell命令:</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> -----------------------</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> yum命令执行完毕,tomcat6就安装完成;</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> tomcat6启动:<span style="line-height:1.5;">yum安装的tomcat6已经自动安装了chkconfig服务的命令,也就是能够采用诸如service httpd start之类的命令启动、中止、重启tomcat6</span></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> -----------------------</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> shell命令:</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> service tomcat6 start|stop|restart</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> -----------------------</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> <strong>tomcat6的配置</strong></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> 因为nginx php-fpm早已安装,根目录也已指定,并且刚好nginx的各个虚拟主机均在/mnt/下,好比:www.jjonline.cn的根目录在/mnt/www 个人博客blog.jjonline.cn在/mnt/blog 以此类推</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> 因此须要配置下tomcat的根目录,在/etc/tomcat6目录下的server.xml文件中,找到</Host>在</Host>以前添加</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> <Context path="" docBase="/mnt/" debug="0"/> </p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> 便可<span style="line-height:1.5;">【本人的配置不具备通用性,仅仅是由于以前的各个虚拟主机的根目录平行放置在/mnt下,因此采用如上配置,tomcat默认端口为8080,须要修改的请自行查找资料】</span><span style="line-height:1.5;">。</span></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> <strong>nginx代理tomcat配置</strong></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> 打开nginx的配置文件,<span style="line-height:1.5;">在server中添加一个location,代码以下:</span></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> <span style="line-height:1.5;">------------------------</span></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> location ~ \.(jsp|jspx|do|wsdl)?$ {</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> proxy_set_header Host $host;</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> proxy_set_header X-Forwarded-For $remote_addr;</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> proxy_pass http://127.0.0.1:8080/<span style="color:rgb(229,51,51);">XXXX</span>$uri;</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> }</p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> <span style="line-height:1.5;">------------------------</span></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> 请注意,tomcat的根目录在/mnt下,而php、html的根目录在/mnt/xxx的目录下,如上述的/mnt/www即为www.jjonline.cn根目录,因此此处<span style="line-height:1.5;">www.jjonline.cn要支持jsp,则须要将上述location中的红色XXXX部分改成www</span></p> <p style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> 本文来至<a href="http://blog.jjonline.cn/" rel="nofollow" style="color:rgb(0,162,202);text-decoration:none;" target="_blank"><img src="http://ww2.sinaimg.cn/square/535e6eb6gw1e4mk5vurvaj2028028q2s.jpg" width="32" height="32" title="晶晶的博客" alt="晶晶的博客" border="0" style="border:0px;"></a></p> <p id="log-copyright" style="font-size:14px;line-height:25px;color:rgb(51,51,51);font-family:'微软雅黑', '宋体', Helvetica, Arial, Verdana;"> 转载请注明:《<a href="http://blog.jjonline.cn/linux/109.html" rel="nofollow" style="color:rgb(0,162,202);text-decoration:none;" target="_blank">centos下nginx代理tomcat,使nginx同时支持php与jsp</a>》</p> </div> </div> </article>css