How to connect node to nginx reverse proxy

Hi all,

I am receiving the following error message by my local node (express) application:

> node ./src/index.js

      throw er; // Unhandled 'error' event

Error: listen EADDRINUSE :::8080
    at Object._errnoException (util.js:1031:13)
    at _exceptionWithHostPort (util.js:1052:20)
    at Server.setupListenHandle [as _listen2] (net.js:1367:14)
    at listenInCluster (net.js:1408:12)
    at Server.listen (net.js:1496:7)
    at Function.listen (/var/www/html/
    at Object.<anonymous> (/var/www/html/
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)

I’ve followed tutorials like How To Set Up a Node.js Application for Production on Ubuntu 14.04 under the impression that by setting my express application to listen to the same port (8080) as the proxy_pass, my client application could request data from “” (without adding any ports to the address) and said request would eventually be transferred to the node application through the nginx reverse proxy.

I’ve attempted to resolve the conflict by changing the express app’s port to 8081 but still receive no requests from the client.

Here some relevant files:


server {
        listen 80;

        root /var/www/html/;

        index index.html;


        location / {
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Fowarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Fowarded-Proto $scheme;
                proxy_cache_bypass $http_upgrade;

               try_files $uri $uri/ =404;


        ServerAdmin somebody@some.where
        DocumentRoot /var/www/html/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const morgan = require('morgan')
const handle = require('./handle.js')
const server = express()


server.get('/getData', (req, res) => {
})'/publish', (req, res) => {


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

The error Error: listen EADDRINUSE :::8080 is due to the fact that Apache is already listening to port 8080:

        ServerAdmin somebody@some.where
        DocumentRoot /var/www/html/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

If you change the port that the Node application is running on to 8081, this also needs to be reflected in the Nginx configuration:


Additionally, if Nginx is only being used as a reverse proxy, these lines could be removed:

        root /var/www/html/;
        index index.html;

They are telling Nginx to service content directly from /var/www/html/ which might cause some issues.

As it seems like you are already using Apache, you might want to look into mod_proxy. With it, you would be able to simplify your set up by removing Nginx from the equation. See: