| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| servers:windows:nginx_php_php-cgi [2026/01/17 04:21] – [PHP-CGI] Sean Rhone | servers:windows:nginx_php_php-cgi [2026/02/25 05:51] (current) – [nginx] Sean Rhone |
|---|
| |
| * nginx ((https://nginx.org/en/docs/windows.html)) | * nginx ((https://nginx.org/en/docs/windows.html)) |
| * PHP + PHP-CGI ((https://windows.php.net/download/)) | * PHP ((https://windows.php.net/download/)) |
| * [[Information:Realm of Espionage]] | * PHP-CGI |
| | * [[information;realm_of_espionage|Realm of Espionage]] |
| |
| ===== Prerequisites ===== | ===== Prerequisites ===== |
| |
| * [[windows;10|Windows 10 (21H2)]] | * [[windows;10_ltsc_server|Windows 10 (21H2)]] |
| |
| ====== Install ====== | ====== Install ====== |
| ===== nginx ===== | ===== nginx ===== |
| |
| * https://nginx.org/en/download.html | * https://nginx.org/en/download.html ([[https://nginx.org/en/CHANGES|CHANGES]]) |
| * Last tested: ''nginx-1.29.4.zip'' | * Last tested: ''nginx-1.29.5.zip'' |
| |
| * Extract to root system drive for ''C:\nginx-1.29.4\nginx.exe'' | * Extract to root system drive for ''C:\nginx-1.29.5\nginx.exe'' |
| |
| "explorer.exe" "%SystemDrive%" | "explorer.exe" "%SystemDrive%" |
| |
| CD "%SystemDrive%\nginx-"*"\" && "nginx.exe" -v | ===== PHP-CGI ===== |
| |
| CD "%SystemDrive%\nginx-"*"\" && "nginx.exe" -t | * https://windows.php.net/download/ ([[https://windows.php.net/downloads/releases/|raw]]) |
| | * https://windows.php.net/qa/ ([[https://windows.php.net/downloads/qa/|raw]]) |
| | * x64 Non Thread Safe |
| | * Last tested: ''php-8.5.1-nts-Win32-vs17-x64.zip'' |
| |
| ==== confs ==== | * Extract to root system drive for ''C:\php-*\php-cgi.exe'' |
| | * Add to user ''Path'' |
| |
| MKDIR "%SystemDrive%\www\nginx\conf" | "explorer.exe" "%SystemDrive%" |
| |
| COPY /Y "%SystemDrive%\nginx-1.29.4\conf\fastcgi_params" "%SystemDrive%\www\nginx\conf" | "SystemPropertiesAdvanced.exe" |
| |
| COPY /Y "%SystemDrive%\nginx-1.29.4\conf\mime.types" "%SystemDrive%\www\nginx\conf" | C:\php-8.5.1-nts-Win32-vs17-x64 |
| |
| ==== Firewall ==== | ====== Firewall ====== |
| |
| DIR "%SystemDrive%\nginx-1.29.4\nginx.exe" | **** |
| |
| "netsh.exe" advfirewall firewall add rule name="nginx" dir="in" action="allow" profile="any" program="%SystemDrive%\nginx-1.29.4\nginx.exe" protocol="tcp" localport="80,443" | CD "%SystemDrive%\nginx-"*"\" && "netsh.exe" advfirewall firewall add rule name="nginx" dir="in" action="allow" profile="any" program="%CD%\nginx.exe" protocol="tcp" localport="80,443" |
| |
| === Delete Rule === | ===== Delete Rule ===== |
| |
| **** | **** |
| "netsh.exe" advfirewall firewall delete rule name="nginx" | "netsh.exe" advfirewall firewall delete rule name="nginx" |
| |
| ===== PHP-CGI ===== | ====== Check Defaults ====== |
| |
| * https://windows.php.net/download/ | ==== nginx ==== |
| * https://windows.php.net/qa/ | |
| * x64 Non Thread Safe | |
| * Last tested: ''php-8.5.1-nts-Win32-vs17-x64.zip'' | |
| |
| * Extract to root system drive for ''C:\php-*\php-cgi.exe'' | **** |
| * Add to user ''Path'' | |
| |
| "explorer.exe" "%SystemDrive%" | CD "%SystemDrive%\nginx-"*"\conf" && "notepad.exe" "nginx.conf" |
| |
| "SystemPropertiesAdvanced.exe" | ==== PHP ==== |
| |
| C:\php-8.5.1-nts-Win32-vs17-x64 | CD "%SystemDrive%\php-"*"-nts-Win32-"*"-x64\" && "notepad.exe" "php.ini-production" |
| | |
| | CD "%SystemDrive%\php-"*"-nts-Win32-"*"-x64\" && "notepad.exe" "php.ini-development" |
| |
| ====== nginx Settings ====== | ====== nginx Settings ====== |
| |
| ===== Folders ===== | ===== confs ===== |
| |
| MKDIR "%SystemDrive%\www\php" | MKDIR "%SystemDrive%\www\nginx\conf" & CD "%SystemDrive%\nginx-"*"\conf" && COPY /Y "fastcgi_params" "%SystemDrive%\www\nginx\conf\fastcgi_params" |
| |
| MKDIR "%SystemDrive%\www\nginx\conf.d" | MKDIR "%SystemDrive%\www\nginx\conf" & CD "%SystemDrive%\nginx-"*"\conf" && COPY /Y "mime.types" "%SystemDrive%\www\nginx\conf\mime.types" |
| |
| MKDIR "%SystemDrive%\www\nginx\default.d" | ===== Folders ===== |
| | |
| | **** |
| |
| MKDIR "%SystemDrive%\www\nginx\vhosts.d" | MKDIR "%SystemDrive%\www\php" "%SystemDrive%\www\nginx\conf.d" "%SystemDrive%\www\nginx\default.d" "%SystemDrive%\www\nginx\vhosts.d" |
| |
| ===== HTTPS Redirect ===== | ===== HTTPS Redirect ===== |
| <code> | <code> |
| server { | server { |
| |
| listen "80" "default_server"; | listen "80" "default_server"; |
| listen "[::]:80" "default_server"; | listen "[::]:80" "default_server"; |
| |
| return "301" "https://$host$request_uri"; | return "301" "https://$host$request_uri"; |
| |
| } | } |
| |
| ===== Non-existent 404 ===== | ===== Non-existent 404 ===== |
| |
| * This prevents unconfigured subdomains from loading assets from other sites ((if a site/URL doesn't exist, it'll 404)) | * This prevents unconfigured subdomains from loading assets from other sites ((if a site/URL doesn't have a ''vhosts.d\*.conf'', it'll 404)) |
| |
| "notepad.exe" "%SystemDrive%\www\nginx\conf.d\non-existent.conf" | "notepad.exe" "%SystemDrive%\www\nginx\conf.d\non-existent.conf" |
| <code> | <code> |
| server { | server { |
| |
| listen "443" "ssl" "default_server"; | listen "443" "ssl" "default_server"; |
| http2 "on"; | http2 "on"; |
| |
| return "404"; | return "404"; |
| |
| } | } |
| |
| add_header "X-Frame-Options" "sameorigin" "always"; | add_header "X-Frame-Options" "sameorigin" "always"; |
| add_header "X-XSS-Protection" "1; mode=block" "always"; | add_header "X-XSS-Protection" "1; mode=block" "always"; |
| add_header "Cache-Control" "no-store, no-transform, public" "always"; | add_header "Cache-Control" "max-age=604800, no-transform, public" "always"; |
| add_header "Referrer-Policy" "same-origin" "always"; | add_header "Referrer-Policy" "same-origin" "always"; |
| add_header "Expect-CT" "max-age=0" "always"; | add_header "Expect-CT" "max-age=0" "always"; |
| |
| # End</code> | # End</code> |
| | |
| | CD "%SystemDrive%\nginx-"*"\" && "nginx.exe" -c "%SystemDrive%\www\nginx\nginx.conf" -t |
| |
| ==== CSP Headers ==== | ==== CSP Headers ==== |
| @echo off | @echo off |
| |
| | TITLE nginx |
| CD "%SystemDrive%\nginx-"*"\" | CD "%SystemDrive%\nginx-"*"\" |
| |
| @echo off | @echo off |
| |
| | TITLE nginx Stop |
| CD "%SystemDrive%\nginx-"*"\" | CD "%SystemDrive%\nginx-"*"\" |
| |
| "nginx.exe" -s "quit" | "nginx.exe" -s "quit" |
| | |
| | TIMEOUT /T "2" /NOBREAK |
| | TASKKILL /IM "nginx.exe" /T /F |
| | |
| | CD "%Temp%" |
| |
| :: End</code> | :: End</code> |
| "nginx.exe" -s "reload" | "nginx.exe" -s "reload" |
| "nginx.exe" -s "reopen" | "nginx.exe" -s "reopen" |
| | |
| | CD "%Temp%" |
| |
| :: End</code> | :: End</code> |
| "%SystemDrive%\www\scripts\nginx\Reload.bat" | "%SystemDrive%\www\scripts\nginx\Reload.bat" |
| |
| ====== Shortcuts ====== | ====== Task Scheduler ====== |
| |
| ===== Autostart ===== | ===== nginx ===== |
| | |
| "explorer.exe" "%AppData%\Microsoft\Windows\Start Menu\Programs\StartUp" | |
| | |
| "%SystemDrive%\www\scripts\nginx\Start.bat" | |
| |
| nginx | * Auto-start |
| |
| SCHTASKS /Create /SC "ONLOGON" /TN "nginx" /TR "%SystemDrive%\www\scripts\nginx\Start.bat" /F | SCHTASKS /Create /SC "ONLOGON" /TN "nginx" /TR "%SystemDrive%\www\scripts\nginx\Start.bat" /F |