Setting Up Nginx in Ubuntu
This post describes how to setup nginx in ubuntu running in local system, AWS, GoolgeCloud or any cloud platform- Login into system
- Update your package
sudo apt update
- Install nginx
sudo apt install nginx
- Start nginx
sudo service nginx start
- Check if nginx running
- In Browser open
http://localhost
- In terminal run command
curl localhost
-
In both cases you will see nginx welcome page.
- In Browser open
- Make nginx route traffic to some server
- go to dir
cd /etc/nginx/sites-available/
- create file
vi myapp
- add route inside the file
server { listen 80; server_name www.androidlearner.com androidlearner.com; location / { proxy_pass http://localhost:5000; # proxy_redirect off; # proxy_http_version 1.1; # proxy_set_header Upgrade $http_upgrade; # proxy_set_header Connection "upgrade"; # proxy_set_header Host $host; } location /backend/ { proxy_pass http://localhost:3000/; # proxy_redirect off; # proxy_http_version 1.1; # proxy_set_header Upgrade $http_upgrade; # proxy_set_header Connection "upgrade"; # proxy_set_header Host $host; } }```
- go to dir
- create link of this file inside
/etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
- Reload nginx to reflect the changes
sudo service nginx reload
Nginx is setup in the system.
Please ensure your firewall is properly setup