Last active
January 5, 2023 02:57
-
-
Save KebabLord/3c87ab64ef45b4e65720993e9a8136a1 to your computer and use it in GitHub Desktop.
Use Apache as a forward http proxy server as a squid alternative for Windows with a basic username & password authentication. Don't use squidNT since it's not properly maintained and is literally ran under an emulator which is slow. Don't pay for http proxy servers, apache is free and faster. This script downloads and completely configures apach…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script downloads Apache Web Server and configures it to work as a forward http proxy server with basic authentication. | |
# In order to run this script you need to enable powershell scripting by opening the cmd as administrator, | |
# and running this command: powershell Set-ExecutionPolicy RemoteSigned | |
# After that just right click to this file and click to "Run With Powershell" | |
# WebProxy runs on port 80, tested on windows 11. | |
# Check VCRedist current version | |
$OS= if ( ${env:ProgramFiles(x86)} ) {"\WOW6432Node"} else {"\"} | |
$vcredist = Get-ItemProperty -Path "HKLM:\SOFTWARE$OS\Microsoft\VisualStudio\14.0\VC\Runtimes\x86" -ErrorAction SilentlyContinue -ErrorVariable eVcRedist | |
if ($eVcRedist -Or ($vcredist.Bld -le 24215) ) { | |
echo "Recent version of VCredist doesn't seem to be installed." | |
echo "Download the latest from: https://aka.ms/vs/17/release/VC_redist.x64.exe" | |
Read-Host -Prompt "(Press any key to close this window)" ; exit | |
} | |
else { echo "VCredist seems update." } | |
# Check if C:\Apache24 already exists | |
if (Test-Path -Path "C:\Apache24") { | |
echo 'WARNING: There is already an Apache24 folder in C:\Apache24' | |
$question = 'Do you want me to rename it as Apache24_old and continue?' | |
$choices = '&Yes', '&No' | |
$decision = $Host.UI.PromptForChoice('', $question, $choices, 1) | |
if ($decision -ne 0) { exit } | |
if (Test-Path -Path "C:\Apache24_old") { | |
echo "But there is already a Apache24_old folder, please backup or remove it before running this script." | |
Read-Host -Prompt "(Press any key to close this window)" ; exit | |
} | |
New-Item "C:\Apache24_old" -Type Directory | Out-Null | |
Get-ChildItem -Path "C:\Apache24" | Move-Item -Destination "C:\Apache24_old" -Force | Out-Null | |
Remove-Item -Path "C:\Apache24" -Force | Out-Null | |
} | |
# Download and extract the latest httpd-X.X.X-win64-VSXX.zip | |
mkdir tmp | Out-Null; cd tmp | |
echo "Downloading Apache." | |
$useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" | |
(Invoke-WebRequest "https://www.apachelounge.com/download/" -UserAgent $useragent ).content -match '\/download\/.*?zip' | Out-Null | |
Invoke-WebRequest -URI "https://www.apachelounge.com$($Matches.0)" -UserAgent $useragent -OutFile .\apache.zip | |
Expand-Archive .\apache.zip | |
mv .\apache\Apache24\ C:\ ; cd .. ; rm -r -fo .\tmp | |
cd C:\Apache24\conf | |
# Configure Apache Web Server | |
$activate_module_list = "mod_access_compat.so,mod_proxy.so,mod_proxy_connect.so,mod_proxy_http.so,mod_ssl.so,mod_socache_shmcb.so".split(",") | |
foreach ($m in $activate_module_list) { | |
$line=(cat 'httpd.conf') -match "#.*?$($m)" | |
if ( ! $line){ continue } | |
(gc 'httpd.conf' ) -replace "$line", "$($line.substring(1))" | Out-File -encoding ascii 'httpd.conf' | |
} | |
echo ' | |
SSLSessionCache "shmcb:${SRVROOT}/logs/ssl_scache(512000)" | |
SSLSessionCacheTimeout 300 | |
<IfModule mpm_winnt_module> | |
ThreadsPerChild 1920 | |
MaxConnectionsPerChild 0 | |
</IfModule> | |
ServerName localhost | |
KeepAlive On | |
MaxKeepAliveRequests 0 | |
TimeOut 300 | |
ProxyRequests On | |
ProxyVia On | |
<Proxy *> | |
Order deny,allow | |
Allow from all | |
AuthType Basic | |
AuthName "Password Required" | |
AuthUserFile password.file | |
AuthGroupFile group.file | |
Require group usergroup | |
</Proxy> | |
' | Out-File -Append -encoding ascii -FilePath httpd.conf | |
# Create Users & Passwords | |
cd .. | |
$username = Read-Host -Prompt 'New Proxy Username' | |
.\bin\htpasswd.exe -c password.file $username | |
echo "usergroup: $username" | Out-File -Append -encoding ascii -FilePath group.file | |
# Finalise | |
echo "Configuration successful! You can now start C:\Apache24\bin\httpd.exe | |
Build Info: | |
- Default port of server is 80 | |
- access and error logs are located in C:\Apache24\logs | |
- accounts password file is located in C:\Apache24\password.file | |
- accounts group file is located in C:\Apache24\group.file | |
" | |
Read-Host -Prompt "(Press any key to close this window)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment