Linux – Nodejs/Apache config for proxy pass

apache-2.2apache-2.4centoslinuxnode.js

I want to use Nodejs/Apache proxy pass to serve my APIs, but after add below apache(httpd) config, it seems that config not working.

OS:

CentOS 6

/etc/httpd/conf/httpd.conf:

...
<VirtualHost *:80>
   ServerName example.com
   ServerAlias www.example.com

   DocumentRoot /home/MyUser/public_html
   <Directory />
      Options -Indexes +FollowSymLinks
      AllowOverride None
      Require all granted
   </Directory>

   ProxyRequests Off
   ProxyPreserveHost On
   ProxyVia Full
   <Proxy *>
      Require all granted
   </Proxy>

   <Location /api>
      ProxyPass http://MyVpsIp:1337
      ProxyPassReverse http://MyVpsIp:1337
   </Location>

</VirtualHost>
...

after:

sudo service httpd restart

Open example.com/api in the browser:

Not Found
The requested URL /api was not found on this server.

EDIT: when I open example.com:1337/api in the browser, everything is ok! but I want example.com/api

Best Answer

The proxy target needs to end with a slash. Try this:

ProxyPass /api/ http://132.159.25.21:8080/
ProxyPassReverse /api/ http://132.159.25.21:8080/
Related Topic