jetty运行PHP,在嵌入式Jetty(Embedded Jetty)中部署FastCGI Servlet载入PHP程序

这段时间由于服务器架构,需要研究在Java基础上的Jetty中部署PHP程序(Wordpress,Discuz)

在网上查了很多资料,都是用httpd或者nginx当前段Web Server,Jetty在后台服务器的。介于我之前用的嵌入式Jetty(embedded jetty),所以并不适合这种解决方案。

后来又搜索了一下,发现Jetty原来本身就有这个支持:

http://www.eclipse.org/jetty/documentation/9.2.7.v20150116/configuring-fastcgi.html

http://lutaf.com/141.htm

https://gutspot.com/2014/06/24/%E6%B5%8B%E8%AF%95jetty%E7%9A%84fastcgi%E6%94%AF%E6%8C%81/

由于官方说明给的是XML形式的配置,我把它转了如下的Java形式,这里特别注意两个servlet都要设置成AsyncSupported = true,不然Jetty会报错

public WebAppContext phpWebAppContext() throwsException {

String root= "/root/php/yourPHPScriptLocation";

WebAppContext ctx= newWebAppContext();

ctx.setContextPath("/php");

ctx.setResourceBase(root);

ctx.setWelcomeFiles(new String[]{"index.php"});

ServletHolder defaultServletHolder= new ServletHolder(DefaultServlet.class);

defaultServletHolder.setAsyncSupported(true);

ctx.addServlet(defaultServletHolder,"/");

ServletHolder proxyHolder= new ServletHolder(FastCGIProxyServlet.class);

proxyHolder.setAsyncSupported(true);

proxyHolder.setInitParameter("proxyTo", "http://localhost:9000");

proxyHolder.setInitParameter("scriptRoot", root);

proxyHolder.setInitParameter("scriptPattern", "(.+?\\.php)");

ctx.addServlet(proxyHolder,"*.php");returnctx;

}

之后在服务器上启动,用服务器自带的Package Manager就可以下载到。

我启动了以后一切都正常,没有报错,可是显示页面的结果却一直是404 File Not Found。我查了半天,感觉设置都是对的,而且php-fpm的access log也成功显示接到请求了。

究竟什么原因呢??查了半天,在php-fpm的配置文件里看到这一段(样例配置文件可以看这里:https://github.com/perusio/php-fpm-example-config/):

; Unix user/group of processes

; Note: The user is mandatory. If the group is not set, the default user‘s group

; will be used.

user = apache

group = apache

发现运行的时候主进程和子进程都是以apache运行的,我在好奇心之下,把两个都改成root,然后用了php-fpm -R 运行(-R是允许用root运行)

一试,竟然好了!

真是晕倒,没有权限访问竟然也不提示错误,就说file not found。。。。

昏过去啊。。。。。

原文:http://www.cnblogs.com/littlejedi/p/4334213.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值