How to share port 80 with apache and nodejs

Source: Internet
Author: User
On my server, I built a php server using apache, and some programs are running. Now I am playing with ghost and using nodejs. So the question is, how can we allow them to use port 80 together. SF has an article above: segmentfault. comq100000000702092, but not... on my server, I built a php server using apache, and some programs are running. Now I am playing with ghost and using nodejs. So the question is, how can we allow them to use port 80 together.

There is already an article on SF: Workshop. I found other articles on the Internet and found that they could not meet my requirements.

I used reverse proxy to solve the problem, but found that all requests were forwarded, which is not what I want.

Assume that my domain name is www.hello.com
I want to use a domain name, an IP address, and port 80. You only need to change the access url to specify different web servers (apache and nodejs) what I want to achieve is:
1. www.hello.com or hello.com access my ghost blog site
2. www.hello.com/wechat/wx.php or hello.com/wechat/wx.php?my PHP site

Now let's talk about my server directory settings:
1. the root directory of the php site is in/usr/local/apache/htdocs/. below is the wechat Directory, which is my public account backend server;
2. The ghost site is in/usr/local/apache/htdocs/ghost/and has been started with nodejs. The port is 2386.

Before the ghost site is added, www.hello.com/wechat/ can access the php site normally.

I added this setting in httpd. conf:


  
   ServerAdmin hello@foxmail.comServerName www.hello.comServerAlias hello.comProxyRequests Off
   
        Order deny,allow    Allow from all
       ProxyPass / http://localhost:2386/ max=20 ttl=120 retry=300ProxyPassReverse / http://localhost:2386/ErrorLog "/usr/local/apache/logs/proxy_error.log" 
  

After the above site is added, all my requests are forwarded to the ghost site, that is, www.hello.com/wechat/wx.php is also forwarded to http: // localhost: 2386 /, the Error 404 is not found.

How can I set up to prevent php requests from being forwarded by reverse proxy? Thank you!

Reply content:

On my server, I built a php server using apache, and some programs are running. Now I am playing with ghost and using nodejs. So the question is, how can we allow them to use port 80 together.

There is already an article on SF: Workshop. I found other articles on the Internet and found that they could not meet my requirements.

I used reverse proxy to solve the problem, but found that all requests were forwarded, which is not what I want.

Assume that my domain name is www.hello.com
I want to use a domain name, an IP address, and port 80. You only need to change the access url to specify different web servers (apache and nodejs) what I want to achieve is:
1. www.hello.com or hello.com access my ghost blog site
2. www.hello.com/wechat/wx.php or hello.com/wechat/wx.php?my PHP site

Now let's talk about my server directory settings:
1. the root directory of the php site is in/usr/local/apache/htdocs/. below is the wechat Directory, which is my public account backend server;
2. The ghost site is in/usr/local/apache/htdocs/ghost/and has been started with nodejs. The port is 2386.

Before the ghost site is added, www.hello.com/wechat/ can access the php site normally.

I added this setting in httpd. conf:


  
   ServerAdmin hello@foxmail.comServerName www.hello.comServerAlias hello.comProxyRequests Off
   
        Order deny,allow    Allow from all
       ProxyPass / http://localhost:2386/ max=20 ttl=120 retry=300ProxyPassReverse / http://localhost:2386/ErrorLog "/usr/local/apache/logs/proxy_error.log" 
  

After the above site is added, all my requests are forwarded to the ghost site, that is, www.hello.com/wechat/wx.php is also forwarded to http: // localhost: 2386 /, the Error 404 is not found.

How can I set up to prevent php requests from being forwarded by reverse proxy? Thank you!

Nginx can be used ..

Use nginx php outside your node to communicate with nginx using php-fpm, and use url rule forwarding to fully meet your needs. In other words, Apache reverse proxy can be used, but it is not as easy to use as nginx. Also, when using reverse proxy, node is definitely not the same port as nginx.


  
       ServerName www.test.com    ProxyRequests Off    
   
            Order deny,allow        Allow from all    
       ProxyPass / http://127.0.0.1:9000/    ProxyPassReverse / http://127.0.0.1:9000/
  

Note:

ProxyPass / http://127.0.0.1:9000/ProxyPassReverse / http://127.0.0.1:9000/

It refers/Forwardhttp://127.0.0.1:9000/That is, all requests are forwarded9000Port.

Try to see if this is OK.

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.