0
votes

I have a problem to setup Apache as a reverse proxy for my Express/Node application. The application can be reach in the correct URL but a route with Express parameters got 404 not found.

Here is my server.js configuration for the route:

app.get('/quiver/note/:path', (req, res, next) => {
   const note = getQuiverNote(req.params.path)
   res.json(note)
})

And here my Apache conf for reverse proxy:

<VirtualHost *:80>
   ServerName quiver-node-reader.local
   ProxyRequests Off
   ProxyPreserveHost On
   ProxyVia Full
   ErrorLog "/var/log/httpd/quiver-node-reader.local-error_log"
   CustomLog "/var/log/httpd/quiver-node-reader.local-access_log" common

   <Proxy *>
      #Require all granted
      Order deny,allow
      Allow from all
   </Proxy>

  <Location />
     ProxyPass http://127.0.0.1:8080/
     ProxyPassReverse http://127.0.0.1:8080/
  </Location>
</VirtualHost>

When I browse my app with http://127.0.0.1:8080 everything works fine. When I browse my app via Apache with http://quiver-node-reader.local I reach my app without any problem, but when the route with parameter is call I got 404 this time :(

Example: http://quiver-node-reader.local/quiver/note/data%2Fformat-z%20(dev).qvnotebook%2FC9EBA21F-D425-4C99-BCAB-8B7B20235FF0.qvnote -> this route cannot be reached 404 error http://127.0.0.1:8080/quiver/note/data%2Fformat-z%20(dev).qvnotebook%2FC9EBA21F-D425-4C99-BCAB-8B7B20235FF0.qvnote -> can be reached

Here is the log from Apache :

127.0.0.1 - - [27/Aug/2018:09:48:25 +0200] "GET /quiver/note/data%2Fformat-z%20(dev).qvnotebook%2FC9EBA21F-D425-4C99-BCAB-8B7B20235FF0.qvnote HTTP/1.1" 404 75

1

1 Answers

1
votes

Finally figure out what was my problem. My URL parmaeter is URLENCODED and there is / inside Apache will give 404 not found if option AllowEncodedSlashes is off. More info here https://httpd.apache.org/docs/2.2/en/mod/core.html#allowencodedslashes

Here is my config to get it working

<VirtualHost *:80>
  ServerName quiver-node-reader.local
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyVia Full
  ErrorLog "/var/log/httpd/quiver-node-reader.local-error_log"
  CustomLog "/var/log/httpd/quiver-node-reader.local-access_log" common
  AllowEncodedSlashes On      

  <Proxy *>
     #Require all granted
     Order deny,allow
     Allow from all
  </Proxy>

  <Location />
     ProxyPass http://127.0.0.1:8080/ nocanon
     ProxyPassReverse http://127.0.0.1:8080/        
  </Location>