Install and Configure nginx on Windows

Installing and Running nginx

  1. Download nginx for Windows Download
  2. Extract the downloaded .zip file
  3. Rename the extracted folder nginx
  4. Copy the extracted nginx files to the desired location, for example C:\Program Files\nginx
  5. Open the nginx folder and double click nginx.exe to run the server

Adding PHP Support

  1. Download PHP for Windows (VC15 x64 NTS) Download
  2. Install Microsoft Visual C++
  3. Extract the downloaded .zip file
  4. Rename the extracted folder php
  5. Copy the extracted php folder to the desired location, for example C:\Program Files\PHP
  6. Open the php install location and right click in the white space while holding down the Shift key > Open PowerShell window here
  7. Paste the following command in the PowerShell window to start the PHP CGI process
    .\php-cgi.exe -b 127.0.0.1:9123
  8. Open Windows Explorer and navigate to the nginx installation directory /conf
  9. Edit nginx.conf in a text editor
  10. Add the following lines inside the server object

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9123;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

  11. Save the changes to nginx.conf
  12. Right click the Start button > Run > Type taskkill /f /im "nginx.exe" > Press Enter
  13. Double click nginx.exe to restart the process with PHP support

Running nginx Server on Startup

nginx doesn't currently have the ability to run as a Windows service natively. A simple workaround is to create a scheduled task to start the nginx server on system startup

  1. Open notepad and paste the following into a blank text file
    start "" /b "C:\Program Files\PHP\php-cgi.exe" -b 127.0.0.1:9123
    start "" /b "C:\Program Files\nginx\nginx.exe" -c "C:\Program Files\nginx\conf\nginx.conf"
  2. Save the text file as startup.bat in the nginx installation directory
  3. Click the Start button > Search Task > Click Task Scheduler
  4. Right click the Task Scheduler Library folder in the top left > Create Basic Task
  5. Name the task nginx startup > Click Next
  6. Select When the computer starts > Click Next
  7. Select Start a program > Click Next
  8. Click the Browse... button and navigate to C:\Program Files\nginx\startup.bat
  9. Set the Start in value to C:\Program Files\nginx > Click Next
  10. Click Finish
  11. Reboot to test that nginx with PHP support starts with the system on boot

Source: http://nginx.org/en/docs/windows.html