I have an Apache 2 server installed on my Debian system. The Apache listens on port 80. Then I have a simple nodeJS server listening on port 8080. I want to use the Apache as proxy for the nodeJS server. What I have so far:

/etc/apache2/sites-available/000-default.conf file:

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

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

        <Location />

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


Then I have the nodeJS server in /var/www/html/nodejs/app.js:

const express = require('express')
const app = express()
const port = 8080

app.get('/second', function(req, res){  

app.listen(port, function() { 
    console.log(`Example app listening on port ${port}!`)


and in my /var/www/html/nodejs/public directory I have my static files index.html, second.html and myScript.js

Now... My problem is: if I access the webpage via http://localhost:8080 (i.e. directly without the apache proxy) it works just fine. But on http://localhost:80 (i.e. the apache proxy), it serves me only the index.html file. The other two files are not served and Chrome Network tab shows Status: 502 Proxy Error for them.

So my question is, how can I make it so the Apache proxy sees all these files from public directory so it can send them to my browser? Thanks!


Could you try to add an additional slash at the end of you ProxyPass, like:



  • 1
    holy **** this worked... And to think I spent several hours trying to figure this out. Just to clarify, without the extra / I was trying to get http://localhost:80second.html instead of http://localhost:80/second.html?
    – muliku
    Sep 11 '19 at 13:25
  • Yes, that was exactly what was taking place here.
    – g_bor
    Sep 11 '19 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.