繁体   English   中英

通过Apache Proxy的Express NodeJS服务器,错误404,带有Express参数的路由

[英]Express NodeJS server through Apache Proxy, error 404 for route with express parameters

我在将Apache设置为Express / Node应用程序的反向代理时遇到问题。 可以使用正确的URL到达该应用程序,但是找不到带有Express参数的路由404。

这是我的路由的server.js配置:

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

这是我的反向配置的Apache conf:

<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>

当我使用http://127.0.0.1:8080浏览我的应用程序时,一切正常。 当我使用http://quiver-node-reader.local通过Apache浏览我的应用程序时,我到达应用程序没有任何问题,但是当调用带参数的路由时,我这次得到了404 :(

示例: http://quiver-node-reader.local/quiver/note/data%2Fformat-z%20(dev).qvnotebook%2FC9EBA21F-D425-4C99-BCAB-8B7B20235FF0.qvnote- > 无法达到此路由404错误http://127.0.0.1:8080/quiver/note/data%2Fformat-z%20(dev).qvnotebook%2FC9EBA21F - D425-4C99 - BCAB - 8B7B20235FF0.qvnote- > 可以访问

这是来自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

最后弄清楚我的问题是什么。 我的URL参数是URLENCODED,如果关闭了AllowEncodedSlashes选项,则Apache内的/将找不到404。 此处提供更多信息https://httpd.apache.org/docs/2.2/en/mod/core.html#allowencodedslashes

这是我的配置以使其正常工作

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM