NGINX is a free and open-source server which is known to be very performant. NGINX is also very often used as load balancer and mail server with support to POP3 and IMAP protocols
NGINX vs Apache
NGINX uses by far less memory than Apache and can handle much more requests per second, however, NGINX is harder to install and configure than Apache and third party modules are hard to integrate. NGINX is also not very stable on Windows machines
In this tutorial we will installing NGINX on Windows and making some configuration to run a HTML file with an image
Download the latest version of NGINX for Windows on http://nginx.org and unzip it on the C drive of your computer (For this tutorial we be using NGINX 1.16.0)
Open a windows explorer and go to the NGINX installation directory and create two new folders /data/www and /data/images. Inside /data/www we will create a HMTL file with following content:
1 2 3 4 5 6 7 8 9 10 11 12 |
<html lang="en"> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>NGINX Tutorial</title> </head> <body class="homepage"> <h2>Hokkaido Image</h2> <p>I love Hokkaidos</p> <img src="images/hokkaido.jpg" alt="" /> </body> </html> |
Now inside /data/images we will insert a new image hokkaido.jpg
In the next step we will have to configure the server to properly display our HTML file. Open the NGINX configuration file conf/nginx.conf and overwrite its contents with
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
worker_processes 1; events { worker_connections 1024; } http { server { #listen 8080; location / { root /nginx/data/www; } location /images/ { root /nginx/data; } } } |
Open a command line and then change to the NGINX installation directory to start the NGINX server:
Open a browser and call http://localhost and you should see following site