Recommended way to server nodejs http app (nginx)

SYSTEM INFORMATION
OS type and version 24.04.1
Virtualmin version 7.20.2

Firstly please excuse the previous deleted post - this was user error (I didn’t specify the FQD name in my server name - duh!)

I am trying to serve a node js application. It is running fine on localhost:8080 I create a new site - this is fine. But I don’t know how to configure nginx. My best guess is to try web configure > configure nginx website and then to click on the “proxy settings” button. But the port isn’t accepted as a valid localhost address. Tbh I am not even sure I am in the right place

I have got it working by editing the .conf file - but not sure if this is a “safe” way?

Many thanks

Chris

It is safe. That’s one of the big differences between Virtualmin and some other control panels. Virtualmin parses the config file on every edit, it does not generate configs from a database or whatever.

There’s also the Proxy Paths simplified proxy rule UI, which may or may not be helpful for you. But, generally speaking you can just follow the documentation for the things you’re trying to run, and that will work fine, as long as you adjust for path and user, etc.

Thanks Joe. This is good to know. As different web apps have different nginx setups so having a custom .conf file is pretty necessary for these type use cases I think

I have spent a lot of time trying to get a good, repeatable set up going for virtualmin with nginx proxy pass-throughs. Where I’ve run into trouble is where I have bypassed virtualmin in terms of creating a new virtual server and just done my own thing creating an nginx .conf file and using certbot commands. This never seems to end well. So my current method, if it helps any one (and in case its wrong!) is to:

  • Get the custom app up and running on e.g. localhost:8080 or localhost:8069 or whatever
  • Curl localhost:8080 and make sure all is well
  • Create a new virtual server using virtual min and specify to create an nginix site (this will also issue an ssl cert)
  • manaully edit the automatically gerated .conf file to proxy to the localhost:port address. But making sure I copy the ssl certificate lines from the original conf file to the new conf file
  • Another trick seems to be that although specifying in the config file something like
location / {
    proxy_pass http://localhost:8080;

does work without virtualmin, when the site is a virtualmin site it is necessary to specify the internal IP address instead of localhost.

Anyway, there it is, still emerging so not saying its the best way or anything, but its the only way I’ve found to have virtualmin play nicely with apps like nodejs apps running on the box so far

2 Likes

That’s surprising. I can’t think of why that would be so.

Generally speaking, all the usual ways work with Virtualmin, as long as it is in a virtual host (called a “server” block, in nginx). So, I don’t really have any advice for what went wrong with other ways. :man_shrugging: