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

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.