在嵌入式Jetty(Embedded Jetty)中部署FastCGI Servlet载入PHP程序
這段時間由于服務(wù)器架構(gòu),需要研究在Java基礎(chǔ)上的Jetty中部署PHP程序(Wordpress,Discuz)
在網(wǎng)上查了很多資料,都是用httpd或者nginx當(dāng)前段Web Server,Jetty在后臺服務(wù)器的。介于我之前用的嵌入式Jetty(embedded jetty),所以并不適合這種解決方案。
后來又搜索了一下,發(fā)現(xiàn)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形式的配置,我把它轉(zhuǎn)了如下的Java形式,這里特別注意兩個servlet都要設(shè)置成AsyncSupported = true,不然Jetty會報錯
public WebAppContext phpWebAppContext() throws Exception {String root = "/root/php/yourPHPScriptLocation";WebAppContext ctx = new WebAppContext();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");return ctx; }之后在服務(wù)器上啟動,用服務(wù)器自帶的Package Manager就可以下載到。
我啟動了以后一切都正常,沒有報錯,可是顯示頁面的結(jié)果卻一直是404 File Not Found。我查了半天,感覺設(shè)置都是對的,而且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
發(fā)現(xiàn)運(yùn)行的時候主進(jìn)程和子進(jìn)程都是以apache運(yùn)行的,我在好奇心之下,把兩個都改成root,然后用了php-fpm -R 運(yùn)行(-R是允許用root運(yùn)行)
一試,竟然好了!
真是暈倒,沒有權(quán)限訪問竟然也不提示錯誤,就說file not found。。。。
昏過去啊。。。。。
?
轉(zhuǎn)載于:https://www.cnblogs.com/littlejedi/p/4334213.html
總結(jié)
以上是生活随笔為你收集整理的在嵌入式Jetty(Embedded Jetty)中部署FastCGI Servlet载入PHP程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Weiss】【第03章】练习3.7:有
- 下一篇: PHP Curl transfer cl