
Nginx - Setting up server in UBUNTU
Nginx is a middle layer between application layer and client layer.
Nginx provides
- SSL Compatibles.
- Load Balancing
- Caching
- Compress Data, speed up requests.
- Request queueing
Steps for setting up NGINX
-
Login through SSH to your VM
ssh username@ipaddress
-
Update your Ubuntu Repository
sudo apt-get update
sudo apt-get upgrade -y
-y
indicates yes for question asked during installation -
Adding PPA repository of nginx
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
-
Lets install nginx through command
sudo apt-get install nginx
-
Start Nginx server
sudo service nginx start
-
Now try to access your IP Address in your browser.If everything worked fine, You should see Welcome to nginx! page.
From here you can host Multiple websites
-
We shall go to
/opt
and create folderwww
. In this folder we will be storing all our static web projects./opt$ mkdir www
-
Inside
www
we shall create a project folder with the domain name of the project./opt/www$ mkdir xyz@domain.com
-
We shall create a sample HTML file with name
index.html
<html> <head> <title>Hello world</title> </head> <body> <h1>Hello World</h1> </body> </html>
-
We shall go to
/etc/nginx/sites-available
and create a config file for our website. Create a config file with a domain namevi xyz@domain.com
server { listen 80; server_name xyz@domain.com; access_log /opt/www/xyz@domain.com/access.log; root /opt/www/xyz@domain.com }
- listen: Indicates the port to listen
- server_name: is the domain name
- access_log: is the path you want to store your access logs
- root: is the path where our project files resides
-
Next will go to
sites-enabled
folder. And will create a symbolic link with the config./etc/nginx/sites-enabled$ sudo ln -s /etc/nginx/sites-available/xyz@domain.com xyz@domain.com
-s
indicates symbolic link -
Finally restart your nginx
sudo service nginx restart
-
Now your website is up and running. Try to access your domain in your browser