Экспресс-сервер NodeJS через Apache Proxy, ошибка 404 для маршрута с экспресс-параметрами - PullRequest
0 голосов
/ 27 августа 2018

У меня проблема с настройкой 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, все работает нормально.Когда я просматриваю свое приложение через Apache с http://quiver -node-reader.local , я без проблем достигаю свое приложение, но когда маршрут с параметром называется call, я получил 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

1 Ответ

0 голосов
/ 27 августа 2018

Наконец-то выясни, в чём была моя проблема. Мой URL-адрес parmaeter URLENCODED и есть / внутри Apache выдаст 404 not found, если опция AllowEncodedSlashes выключена. Больше информации здесь 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>

...