Register now and start sharing your code snippets.
-->
Configuring Apache to be a forward proxy
Apache posted about 1 month ago by christian
This configuration makes Apache act as an HTTP proxy:
1 <VirtualHost *:8080> 2 ProxyRequests On 3 ProxyVia On 4 #ProxyRemote * http://...:8080 Uncomment to route requests through another proxy 5 <Proxy *> 6 Order deny,allow 7 Deny from all 8 Allow from all # Not a good idea, set to allowed IP ranges 9 </Proxy> 10 11 CacheRoot "/tmp" 12 CacheMaxExpire 24 13 CacheLastModifiedFactor 0.1 14 CacheDefaultExpire 1 15 16 ServerName my-proxy 17 18 ErrorLog "/var/log/apache2/proxy-error.log" 19 CustomLog "/var/log/apache2/proxy-access.log" common 20 </VirtualHost>
Also read this.
Tips
You can use mod_rewrite to rewrite requests. To rewrite root (/) to /temporary_outage you could use the following rewrite:
1 RewriteCond %{HTTP_HOST} ^(www\.)?xxx\.com 2 RewriteRule /$ http://%{HTTP_HOST}/temporary_outage/ [P,L]
How to link back to current page with or without same parameters (PHP)
Apache posted 5 months ago by christian
1 function link_back($blacklist = array()) 2 { 3 $parameters = split("&", $_SERVER['QUERY_STRING']); 4 5 $uri = array_shift(split("\?", $_SERVER['REQUEST_URI'])); 6 7 $index = 0; 8 9 foreach($parameters as $parameter) 10 { 11 $parameter = split("=", $parameter); 12 13 $name = $parameter[0]; 14 $value = $parameter[1]; 15 16 if(in_array($name, $blacklist)) 17 { 18 unset($parameters[$index]); 19 } 20 21 $index++; 22 } 23 24 if(count($parameters) > 0) 25 { 26 $parameters = "?".join("&", $parameters); 27 } 28 else 29 { 30 $parameters = ''; 31 } 32 33 return $uri.$parameters; 34 }
Usage:
1 # URI is /wow_amazing_code?not_wanted=23&wanted=1 2 3 echo link_back(array('not_wanted')); # prints out /wow_amazing_code?wanted=1
How to change the Apache 2 server signature on Debian Etch
Apache posted 6 months ago by christian
Install mod_security, for some stupid reason it’s not included in Debian Etch, and for some even more stupid reason you’re not allowed to change the value of the Server header.
Anyway, to change the server signature, and enable voodoo magic:
1 <IfModule mod_security2.c> 2 # Basic configuration options 3 SecRuleEngine On 4 SecRequestBodyAccess On 5 SecResponseBodyAccess Off 6 7 # Handling of file uploads 8 # TODO Choose a folder private to Apache. 9 # SecUploadDir /opt/apache-frontend/tmp/ 10 SecUploadKeepFiles Off 11 12 # Debug log 13 SecDebugLog /var/log/apache2/modsec_debug.log 14 SecDebugLogLevel 0 15 16 # Serial audit log 17 SecAuditEngine RelevantOnly 18 SecAuditLogRelevantStatus ^5 19 SecAuditLogParts ABIFHZ 20 SecAuditLogType Serial 21 SecAuditLog /var/log/apache2/modsec_audit.log 22 23 # Maximum request body size we will 24 # accept for buffering 25 SecRequestBodyLimit 131072 26 27 # Store up to 128 KB in memory 28 SecRequestBodyInMemoryLimit 131072 29 30 # Buffer response bodies of up to 31 # 512 KB in length 32 SecResponseBodyLimit 524288 33 34 SecServerSignature "Dummy value" 35 </IfModule> 36
Rails+Mongrel+Apache 2 on Mac OSX Leopard
Apache posted 6 months ago by christian
I use this configuration on my development machine when I need mod_rewrite; it’s not meant for production:
1 <VirtualHost *:80> 2 ServerName dev.xxx.com 3 4 # Enable URL rewriting 5 RewriteEngine On 6 7 # Rewrite index to check for static pages 8 RewriteRule ^/$ /index.html [QSA] 9 10 # Rewrite to check for Rails cached page 11 RewriteRule ^([^.]+)$ $1.html [QSA] 12 13 # Redirect all non-static requests to cluster 14 RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 15 RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L] 16 17 DocumentRoot "/Users/christian/Documents/Projects/xxx/public" 18 <Directory "/Users/christian/Documents/Projects/xxx/public"> 19 Options Indexes FollowSymLinks 20 21 AllowOverride None 22 Order allow,deny 23 Allow from all 24 </Directory> 25 26 </VirtualHost> 27 28 <Proxy balancer://mongrel_cluster> 29 BalancerMember http://127.0.0.1:3000 30 </Proxy>