Nginx is a web server that is very popular with Linux and BSD systems. It can also be installed on Windows as long as you can live with performance limitations that have not been mitigated so far. You can still host a web server or a customer/employee portal from the comfort of your Windows laptop. To install and run Nginx successfully on Windows, follow the steps below.
Tip: if all you need is a local web server to test your applications, here are the ways to set up a local web server in Windows.
Installing Nginx in Windows
To get started, we will need to install Nginx on your Windows laptop or PC. There are no conventional Nginx installers with this operating system. You will need to download one of its online versions and save it to a C: drive location of your PC.
- Select the version you want and download its zip file to your PC. Nginx recommends using the “mainline version” as it comes with the latest features. If you don’t need those features, the most recent stable version will work too.
- Once downloaded, extract the new folder by right-clicking on it. You may also use popular compression software such as 7-zip or WinRAR.
- Move the entire folder that came with the built-in download copy into the C: drive. In this example, we moved it to “Program Files” but it can be saved at any location on your PC including D drive.
- Select and double-click the “Nginx.exe” file. It has now been activated for further use. We will run Nginx from this location as a default web service program.
- If you have enabled Windows SmartScreen filter, it may prevent the Nginx installer from running. Click “More info” to bypass the limitation.
- Click the “Run anyway” text to run the nginx.exe file.
- You may further run into a Windows Defender firewall block screen while running the Nginx server, which has to be allowed by you. Once done, you can readily use Nginx on your Windows device.
Do you know: wondering what is the difference between Nginx and Apache? We have the answers here.
How to Start Nginx on Windows
There are multiple ways to run Nginx on your Windows PC depending on your end use requirements. You can use these methods simultaneously. For example, you can launch the Nginx server using its application file or from PowerShell.
1. Using Nginx Application File
Nginx has a built-in application file that you can double-click as described in above section. You will need to bypass any restrictions due to SmartScreen or Windows Defender.
- Once done, go to your default browser and type localhost. Microsoft Edge is the browser used in the below example.
- If you see a screen saying the Nginx web server is successfully installed and working, it means there were no problems with your Nginx installation in Windows.
- To stop Nginx, you can end it from the Task Manager window. If you can’t terminate it directly from the Processes, right click to select “Go to details.”
- Identify all instances of Nginx.exe and right click to end each task.
- Ignore any warning such as “do you want to end Nginx.exe.” Click “End process” to continue with the termination.
- When you type localhost, you will see a “can’t reach this page” screen on your browser web page.
2. Using PowerShell
The best part of Nginx is that it can run as an automated script from PowerShell and also the Command Prompt. We will demonstrate that for PowerShell below.
- Launch PowerShell in Administrator mode.
- Go back to the folder where you saved the Nginx application, and right-click to go to its Properties. Here you can copy the exact folder path. In this example, it is “C:\nginx-1.25.1\nginx-1.25.1”
- Change the PowerShell directory to point to the above path.
cd Path of Nginx installer
- To initiate the Nginx server, type the following command.
start nginx
- You can view Nginx.exe process instances in Task Manager nested under Windows PowerShell.
- On Windows, Nginx can be run as a standard console app. For managing it, the following simple commands are frequently used:
nginx -s stop | Rapid shutdown |
nginx -s quit | Graceful shutdown |
nginx -s reload | Changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes |
nginx -s reopen | Reopening log files |
- If you encounter any error such as “the command nginx was not found, but does exist in the current location,” PowerShell will prompt you to use a different command. In the following example, we have replaced all instances of
nginx
with/.nginx
, using them to reload and quit the program.
3. Using IIS Manager
You can also use Internet Information Services (IIS) to run Nginx which is a Microsoft web server that serves requested HTML pages or files. In the past, it was compulsory but it’s no longer the case.
- You can enable it in “Turn Windows Features On or Off” in the Control Panel. Check the required fields for “Web Management Tools” and “IIS Management Console.”
- It will take a while for IIS to be enabled on your computer as the changes are applied.
- You will see a success status that “Windows completed the requested changes.”
- You can open IIS Manager directly from the Start menu. Always open it in Administrator mode.
- Here, you will be able to access the default website, which is usually located at “inetpub wwwroot.” This is also known as the web application root. You can look for it in File Explorer through a simple search.
- When you double-click on the “default web site” option in IIS Manager, it should lead to this new folder. Alternatively, you can right-click the menu and select “Explore” for the same result.
- Once your IIS Console is enabled, you can view its webpage by typing localhost on your default browser.
How to Configure Nginx For Windows
To run Nginx in Windows, all desired changes are affected from various strings modified in the “index.html” and “nginx.conf” files in the installation folder. These strings are usually edited using the Notepad text editor, but you can use any other editor such as Atom, Notepad++ or Visual Studio Code. In this case, we will edit the configuration file using Notepad++.
- Go to the folder where you saved your Nginx application. Click the “html” subfolder.
- Right click to select “Edit with Notepad++” for the index.html file.
- You can edit the index.html file in the root folder in a new or separate tab. Change the text to what you want the web server to display on the screen.
- Don’t forget to click the “Save” button on top once you’re done.
- Exit the Nginx.exe program using “End Task” as shown in above section and restart it.
- Type localhost in a browser window. The Nginx web server will highlight the edits you made.
- After this, click “Conf” and right click to select “nginx.conf” followed by “Edit with Notepad++.”
- Find the location of the root and change it from the default html to any other physical path.
To know more about Nginx commands, including the documentation, visit this link.
Example Application of Nginx in Windows
Nginx supports multiple applications in Windows, such as web server, load balancer, reverse proxy, or even host your own Youtube site. The Nginx resources site has a full list of web server applications which you can use to run various applications on Windows PC.
For example, you can use Nginx in Windows to link to a webpage such as a customer login page. Once you make the configuration changes in the “nginx.conf” file, your end users will be able to access the login page on their end.
- Go back to the “nginx.conf” file shared in the previous section. Instead of “somename,” you need a domain name for the server to access.
- Go to “location” and modify the text using an “api,” followed by a proxy server added with an “http” ping. This should point to any login page you want this page to direct to. Here we have a “proxy_pass” field which has a “127.0.0.1′ URL local to your Windows machine.
- Save the file and run the “Nginx.exe” program in Admin mode.
- As shown here, 127.0.0.1 is what Nginx.exe points to, and this is the path you can modify in above Conf file to point to an external customer portal or web server.
Frequently Asked Questions
How to solve Nginx's "The system cannot find the path specified" error in Windows?
Sometimes while running Nginx in Windows Command Prompt/PowerShell, you may run into a “System cannot find the path specificed” error. To avoid it, go to the folder where you saved the Nginx.exe application, and right click on it to view its properties, which will give the exact path it is located. There could be a few other reasons behind this, and we have a detailed guide to fix the issue.
What are the disadvantages of Nginx in Windows?
Even though it supports Windows, Nginx is not the best choice for the operating system. Its biggest disadvantage is that it’s incapable of multitasking. For instance, you can execute only one process at a time. If you are running a web server, your Windows machine will be occupied with that one task. This poses challenges in scalability, and one Windows device isn’t sufficient to work with Nginx.
How popular is Nginx?
Nginx is one of the leading web server companies today. Also, it is faster, can handle more concurrent issues and is reliable. To summarize, if you have a simple website you want to connect to Nginx, you can do it right now without any problems. Read on to check out the comparison of Nginx to OpenLiteSpeed.
All images and screenshots by Sayak Boral.
Our latest tutorials delivered straight to your inbox