appy-one / acebase-server

A fast, low memory, transactional, index & query enabled NoSQL database server for node.js that easily syncs with browser and node.js clients and servers
MIT License
32 stars 14 forks source link

Setting up Nginx #73

Open LebedevIV opened 1 year ago

LebedevIV commented 1 year ago

The AceBase server, when installed on a remote server, created a config for nginx: server { listen 80; listen [::]:80; location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }

... which listens on port 80, therefore, external requests from a browser with the specified port http://server_address:3000 are not redirected to the server's local services - the port will have to be removed so that the address http://server_address remains - only then it will be redirected to nginx to internal 3000 port. In addition, calls to the server AceBaseClient('95.140.158.78', 3000, 'server', false) also caused errors. I added in the config another server to listen on the port 3000 : server { listen 3000; location / { proxy_pass http://localhost; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } Now you can access from the browser with the port http://server_address:3000, and without the port http://server_address.

Correct me if I did something wrong, and is nginx even needed? In this manual, I did not find the environment setting for remote hosting of the AceBase server anywhere.

I'm not a very educated person - I'm trying to replace FireBase Realtime with AceBase. I would be very grateful if for people like me to slightly lower the entry threshold with slightly more detailed step-by-step instructions, it is better to use a through example of installation, for example, on Ubuntu with Node.js . I think AseBase will become very popular with the threshold of entry close to FireBase Realtime.

Many thanks and best wishes!

appy-one commented 1 year ago

I don't use nginx myself, but generally speaking you'd want to run your AceBase server on a local port on localhost (such as 3000), and have a reverse proxy server (what nginx is) forward public port 80 and/or 443 traffic to that local port. This way, a client/user connects to yourserver.com and nginx will port forward the connection on port 80/443 to internal port 3000. yourserver.com:3000 will not be publicly available this way because it is bound to localhost (127.0.0.1) only.

The effect of this is that you can run multiple servers on ports 80/443, and forward them to the right local port depending on the used host name: db1.myserver.comcan forward to local port 3001, db2.myserver.com to port 3002 and so on

LebedevIV commented 1 year ago

Yes, nginx does that. And then a logical solution comes: do not need to change the nginx config and add listening on an external port equal to the internal one. Instead, when connecting to the server, instead of the internal port, specify port 80: const db = new AceBaseClient('95.140.158.78', 80, 'default', false); Dear Ewout, and in what environment do you prefer to deploy AceBase server? Maybe you have ready-made working images or configs, dockers? As I said, I have this Ubuntu 22.04 with Node.js 19, bundled with nginx, since Ubuntu is recommended for Node.js