Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I add an node express proxy server to rails app deployed on DigitalOcean via Classic Hatchbox using an nginx config file?

Alfred Montalvo Jr asked in Servers

I’ve added an node express proxy server to an Ubuntu Digitalocean server that is used by my rails app and is deployed via Classic Hatchbox app that utilizes an nginx configuration file.

The node express proxy server is running on port 7000 on the DO Ubuntu server and I can view the get response from the express proxy server without any problems when I use the IP address for the Ubuntu server in the URL (xxx.x.x.x:7000/folder/file.html).

And I’m getting the following errors on the browser window when I try to access the node express proxy server on port 7000 via my rails app.

"Unable to connect ... can’t establish a connection to the server at 127.0.0.1:7000"

and

"Unable to connect ... can’t establish a connection to the server at localhost:7000"

I've tried adding the nginx server block below to the sites-enabled nginx config file and the rails website goes down without any errors and I'm unable to find a log file on the Ubuntu server to try and debug the problem with nginx.

I also executed the following command (sudo nginx -t) after saving the update below to the nginx config file and it executed without any errors.

server{
listen 7000;
server_name wach.quest;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:7000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# location /overview {
# proxy_pass http://127.0.0.1:7000$request_uri;
# proxy_redirect off;
# }
}
}

Is there any way that I can add an express proxy server running locally on port 7000 to my rails app via an update to the nginx config file?

I have listed the environment specs below:

OS : Ubuntu 20.04
Classic Hatchbox/NGINX
rails: 6.1.7.1
ruby : 3.0.0
node : express, cors and axios

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.