我的服务器上用apache搭建了php的服务器,已经有程序在跑了,现在在玩 ghost,用的是nodejs。那么问题来了,如何让他们同用80端口。
SF上面已经有一篇文章:http://segmentfault.com/q/1010000000702092,但是不符合我的要求,设置后无法达到效果,所有请求都被转发了。网上找了其他的文章,都发现不能符合我的要求。
我用了反向代理来解决,但是发现所有请求都被转发了,这不是我想要的。
假设我的域名是www.hello.com
我想通过一个域名,一个ip地址,80端口,只需要改变访问的url就能指定到不同的web服务器(指的是apache和nodejs) 我要实现的效果是:
1、www.hello.com或者hello.com访问我的ghost博客站点
2、www.hello.com/wechat/wx.php 或 hello.com/wechat/wx.php访问我的php站点
现在说说我的服务器目录设置:
1、php站点根目录在 /usr/local/apache/htdocs/,下面有wechat这个目录,是我的微信公众号后台服务器;
2、ghost站点在 /usr/local/apache/htdocs/ghost/,已经用nodejs启动了它,端口是2386。
在新增ghost站点之前,www.hello.com/wechat/ 是可以正常访问php站点的。
我在httpd.conf中加了这个设置:
<code><virtualhost> ServerAdmin hello@foxmail.com ServerName www.hello.com ServerAlias hello.com ProxyRequests Off <proxy> Order deny,allow Allow from all </proxy> ProxyPass / http://localhost:2386/ max=20 ttl=120 retry=300 ProxyPassReverse / http://localhost:2386/ ErrorLog "/usr/local/apache/logs/proxy_error.log" </virtualhost></code>
加了上述站点后,我的所有请求都被转发到ghost站点去了,也就是www.hello.com/wechat/wx.php 也被 转发到了 http://localhost:2386/,提示找不到网页404错误。
请问我要如何设置才能让php的请求不被反向代理转发?谢谢!
回复内容:
我的服务器上用apache搭建了php的服务器,已经有程序在跑了,现在在玩 ghost,用的是nodejs。那么问题来了,如何让他们同用80端口。
SF上面已经有一篇文章:http://segmentfault.com/q/1010000000702092,但是不符合我的要求,设置后无法达到效果,所有请求都被转发了。网上找了其他的文章,都发现不能符合我的要求。
我用了反向代理来解决,但是发现所有请求都被转发了,这不是我想要的。
假设我的域名是www.hello.com
我想通过一个域名,一个ip地址,80端口,只需要改变访问的url就能指定到不同的web服务器(指的是apache和nodejs) 我要实现的效果是:
1、www.hello.com或者hello.com访问我的ghost博客站点
2、www.hello.com/wechat/wx.php 或 hello.com/wechat/wx.php访问我的php站点
现在说说我的服务器目录设置:
1、php站点根目录在 /usr/local/apache/htdocs/,下面有wechat这个目录,是我的微信公众号后台服务器;
2、ghost站点在 /usr/local/apache/htdocs/ghost/,已经用nodejs启动了它,端口是2386。
在新增ghost站点之前,www.hello.com/wechat/ 是可以正常访问php站点的。
我在httpd.conf中加了这个设置:
<code><virtualhost> ServerAdmin hello@foxmail.com ServerName www.hello.com ServerAlias hello.com ProxyRequests Off <proxy> Order deny,allow Allow from all </proxy> ProxyPass / http://localhost:2386/ max=20 ttl=120 retry=300 ProxyPassReverse / http://localhost:2386/ ErrorLog "/usr/local/apache/logs/proxy_error.log" </virtualhost></code>
加了上述站点后,我的所有请求都被转发到ghost站点去了,也就是www.hello.com/wechat/wx.php 也被 转发到了 http://localhost:2386/,提示找不到网页404错误。
请问我要如何设置才能让php的请求不被反向代理转发?谢谢!
用nginx 可以做到..
在你的node外面使用nginx php用php-fpm和nginx通信,利用url规则转发完全满足你的需求。话说回来Apache的反向代理其实也可以,只是不如nginx简单好用速度快。还有在使用反向代理的时候node肯定不是和nginx同一个端口的啦。
<code><virtualhost> ServerName www.test.com ProxyRequests Off <proxy> Order deny,allow Allow from all </proxy> ProxyPass / http://127.0.0.1:9000/ ProxyPassReverse / http://127.0.0.1:9000/ </virtualhost> </code>
请注意看这里:
<code>ProxyPass / http://127.0.0.1:9000/ ProxyPassReverse / http://127.0.0.1:9000/ </code>
是指将/
转发到http://127.0.0.1:9000/
也就是将所有的请求都转到9000
端口了。
试下这样子是否ok。
<code>ProxyPass / http://127.0.0.1:2386/ ProxyPassReverse / http://127.0.0.1:2386/ ProxyPass /wechat/wx.php http://localhost:80/ ProxyPassReverse /wechat/wx.php http://localhost:80/ </code>

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
