Question

How to set up nodejs websocket server alongside "ubuntu wordpress" install

This will be the 3rd time I’ve typed this as DO just throws it in the garbage after I submit.

I have a droplet that was installed with the wordpress image. I have installed nodejs on the droplet and now I’m running an nodejs websocket server from /var/www/server/. I am hosting the client at /var/www/html/client/ but it will not connect to the websocket server.

After 10+ hours of searching, I think I’ve narrowed it down to something to do with the apache http-proxy but every configuration I’ve tried in the /sites-available/000-default.conf file have failed.

What am I doing wrong? Can somone point me in the correct direction? Thank you.


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.

KFSys
Site Moderator
Site Moderator badge
November 8, 2022
Accepted Answer

Hi @hidinglapisclam,

You’ll need to configure a Reverse Proxy for your NodeJS server as it listens on a specific port. Usually, when talking about Reverse Proxies, Nginx is the go to WebSerivce. There is even a tutorial on how to add NodeJS with Reverse Proxy to your Droplet here;

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-22-04

If you however whish to use Apache, then your apache config should look something like this:

  1. <VirtualHost *:80>
  2. ServerName your-server-ip
  3. ProxyRequests Off
  4. ProxyPreserveHost On
  5. ProxyVia Full
  6. <Proxy *>
  7. Require all granted
  8. </Proxy>
  9. ProxyPass / http://127.0.0.1:8000/
  10. ProxyPassReverse / http://127.0.0.1:8000/
  11. </VirtualHost>

Where the ProxyPass would have your localhost IP address and the port you’ve selected your NodeJs instance to work. The above would code would be integrated with your website’s Apache config in the /etc/apache2/sites-available/ folder.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.