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

  1. Login through SSH to your VM

    ssh  username@ipaddress
  2. Update your Ubuntu Repository

    sudo apt-get update
    sudo apt-get upgrade -y
    -y indicates yes for question asked during installation
  3. Adding PPA repository of nginx

    sudo add-apt-repository ppa:nginx/stable
    sudo apt-get update
  4. Lets install nginx through command

    sudo apt-get install nginx
  5. Start Nginx server

    sudo service nginx start
  6. 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

  1. We shall go to /opt and create folder www. In this folder we will be storing all our static web projects.

    /opt$ mkdir www
  2. Inside www we shall create a project folder with the domain name of the project.

    /opt/www$ mkdir xyz@domain.com
  3. 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>
            
  4. We shall go to /etc/nginx/sites-available and create a config file for our website. Create a config file with a domain name vi 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

  5. Next will go to sites-enabledfolder. 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
  6. Finally restart your nginx

    sudo service nginx restart
  7. Now your website is up and running. Try to access your domain in your browser