Setting up an NGINX web server on a windows machine

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 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:

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

Open a command line and then change to the NGINX installation directory to start the NGINX server:

C:>cd nginx

C:\nginx>start nginx

Open a browser and call http://localhost and you should see following site

Configuring your web server with .htaccess

A .htaccess file helps you to configure your web server, such as the Apache web server.

In a .htaccess file, you can declare rewrite rules, prevent image hotlinking, handle bad http requests (404 Not Found), and so on.

You can even use htaccess for basic authentication along with a .htpassword file where you can store usernames and passwords.

The configuration in the .htaccess file affects the current directory including its subdirectories. You can override the .htaccess file in the subdirectories by simply declaring another .htaccess file

Here are some examples:

Handle a bad request (404 Not Found)


Use htaccess for basic authentication (Grant access only to user: gunther with password: today)



Redirect all requests to news/url to news.php?url=url