Most common applications are able to run as web server on their own, but the Nginx webserver is able to provide following main benefits from these features:
- Load Balancing
- Increased Security
- Better Performance
- Easy Logging and Auditing
- Encrypted Connection
If you already have installed nginx and nodejs in your server, you can configure your reverse proxy like this:
Open the "default" config file:
sudo nano /etc/nginx/sites-available/default
Write appropriate configs there:
server {
# optional
client_max_body_size 30M;
listen 80 default_server;
listen [::]:80 default_server;
# some static directory path
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
# You can leave this _
# server_name _;
# but if you have already connected your domain with your server:
server_name example.com www.example.com;
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;
}
}
Make sure you've successfully tested your configs after last changes:
sudo nginx -t
Restart Nginx
sudo service nginx restart
# or
sudo systemctl restart nginx
Run your app and check the website.
Hope it will work, if any issues, let me know with your comment.
About the local environment: no need to do anything. You can work on your project as you did before. Nothing to do for local. Just connect that to the remote git origin and restart your node-server after any changes.
It's a good practice to connect your server project with your remote origin via CI/CD pipelines.