-
-
Save junaidulqayyumqureshi/0b19a236dc630ef9d3b2e69d33118de2 to your computer and use it in GitHub Desktop.
Server management commands |
NGINX Configuration for Nodejs API
- To deploy a nodejs api, go to
/etc/nginx/sites-available
, and create a new file. Add following contents to it:
upstream mynodeapp {
server 127.0.0.1:3003;
}
server {
#server_name _; #Uncomment this if you want to keep it on ip
#server_name domain.com www.domain.com; #Uncomment this if you want to deploy on a domain
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://mynodeapp;
}
}
-
Make sure that the port you provide is the one you want to host your application on. In this case, port is 3003
-
This application will host directly on ip with port, and not on any subdomain
-To host this application on a domain, instructions are given in the above snippet -
After setting the site file, enable it by:
sudo ln -s /etc/nginx/sites-available/[filename] /etc/nginx/sites-enabled/
-
Test nginx configuration:
sudo nginx -t
If there is an error, this command will show the error -
Restart nginx:
sudo systemctl restart nginx
NGINX Configuration for Web Portal
- To deploy a web portal, go to
/etc/nginx/sites-available
, and create a new file. Add following contents to it:
server {
listen 81;
#server_name _; #Uncomment this if you want to keep it on ip
#server_name domain.com www.domain.com; #Uncomment this if you want to deploy on a domain
root /var/www/stg.admin/build; #Path of the webportal
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
If you DO NOT provide a port number, it will host on port 80 and if there is already a website hosted on same port, nginx will present error
-
Make sure that the port you provide is the one you want to host your application on. In this case, port is 81
-
This application will host directly on ip with port, and not on any subdomain
-To host this application on a domain, instructions are given in the above snippet -
After setting the site file, enable it by:
sudo ln -s /etc/nginx/sites-available/[filename] /etc/nginx/sites-enabled/
-
Test nginx configuration:
sudo nginx -t
If there is an error, this command will show the error -
Restart nginx:
sudo systemctl restart nginx
Set folder permissions
sudo chown -R www-data:www-data /var/www/path;
sudo chmod 600 /var/www/path/.env;
Postgresql Remote Connections
To adding new ip to postgres remote connections
cd /etc/postgresql/16/main
(Version can be changed from 16)sudo nano pg_hba.conf
host all all 110.93.0.0/16 md5
-To add absolute ip address, replace with actual ip address
sudo systemctl restart PostgreSQL