while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8080; done
Showing posts with label webserver. Show all posts
Showing posts with label webserver. Show all posts
Monday, 9 February 2015
One line web server
The following one line script will create a web server running on port 80 using nc (netcat):
Labels:
Command Line,
Linux,
netcat,
Scripting,
webserver
Possibly Related Posts
Wednesday, 16 July 2014
Source IP based reverse proxy
If you want to proxy some source IP ranges/subnets to one server and onther subnets to go to a different server, you can do this using mod_rewrite for proxying. You will have to setup a rewrite condition based on the source IP and a rewrite rule with the [P] flag. Something like this should work:
If you're using Apache 2.4 or newer you can also achieve this with the following configuration:
RewriteCond %{REMOTE_ADDR} ^10\.2\.One possible scenario for this if you want to migrate your users from server A to server B but you want to migrate one IP range at the time.
RewriteRule ^/(.*) http://old-app/$1 [P]
ProxyPassReverse / http://serverA/
RewriteCond %{REMOTE_ADDR} ^10\.3\.
RewriteRule ^/(.*) http://new-app/$1 [P]
ProxyPassReverse / http://serverB/
If you're using Apache 2.4 or newer you can also achieve this with the following configuration:
<If "-R '10.2.0.0/16'">
ProxyPassReverse / /http://serverA/
</If>
<ElseIf "-R '10.3.0.0/16'">
ProxyPassReverse / /http://serverB/
</ElseIf>
<Else>
ProxyPassReverse / /http://serverC/
</Else>
Possibly Related Posts
Tuesday, 15 July 2014
Preserving client ip with apache reverse proxy
The first thing that I thought of was the “X-Forwarded-For” headers, which is an HTTP header inserted into the original HTTP GET request whose value is equal to the client’s public IP. Turns out apache reverse proxy inserts this header by default. So we somehow need to instruct the backend server itself to provide the application with the correct client IP.
If your backend server is a Tomcat server the solution cam be using the RemoteIP tomcat valve.
It’s quite simple to configure in that all that needs to be done is to modify tomcat server.xml to recognise original client IP rather than the proxy IP by adding the following to server.xml:
<Valve className="org.apache.catalina.valves.RemoteIpValve" internalProxies="127\.0\.0\.1" />
make sure to change 127.0.0.1 to the address of the apache reverse proxy.
The application could now recognise the original client IP.
The apache equivalent of the above method is using mod_rpaf for Apache 1.3 & 2.2.x and mod_remoteip for Apache 2.4 and 2.5.
These apache modules can be used to preserve both remote IP/HOST. Internally they use X-Forwarded-For header to detect a proxy in it’s list of known proxies and reset the headers accordingly. This works with any proxy server in the front end provided that the proxy server sets X-Forwarded-For header.
To use mod_rpaf, install and enable it in the backend server and add following directives in the module’s configuration:
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1
Remote IP is automatically preserved when RPAFenable On directive is used. RPAFsethostname On directive should be used to preserve host and RPAFproxy_ips is the list of known proxy ips.
Restart backend apache server and you are good to go.
For mod_remoteip, it’s a bit similar, the configuration should look something lke this:
RemoteIPHeader X-Real-IP
RemoteIPInternalProxy 1.2.3.4
RemoteIPInternalProxy 5.6.7.8
mod_remoteip however has a lot more configuration options.
When the proxy server is an Apache, ProxyPreserveHost directive in mod_proxy can be used to preserve the remote host not the remote ip. This is useful for situations where name based virtual hosting is used and the backend server needs to know the virtual name of host.
Open mod_proxy configuration file of your proxy server and enter directive, ProxyPreserveHost On, and restart your apache instance.
Possibly Related Posts
Wednesday, 31 August 2011
Apache reverse proxy of virtual hosts
Here you have a simple example on how to create a vhost for a reverse proxied site:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName blue.domain.com
ProxyRequests off
ProxyPass / http://blue.internal.domain.com/
ProxyPassReverse / http://blue.internal.domain.com/
</VirtualHost>
<VirtualHost *:80>This is also useful if you have a tomcat or anything else running on a different port and you want to serve everything on the same port:
ServerName red.domain.com
ProxyRequests off
ProxyPass / http://red.internal.domain.com/
ProxyPassReverse / http://red.internal.domain.com/
</VirtualHost>
<VirtualHost *:80>
ServerName tom.domain.com
ProxyRequests off
ProxyPass /myapp http://localhost:8080/myapp
ProxyPassReverse /myapp http://localhost:8080/myapp
</VirtualHost>
Possibly Related Posts
Thursday, 4 August 2011
Set nginx maximum upload size
Edit nginx configuration and look for html block.
Inside html block add the following:
Inside html block add the following:
http {
include conf/mime.types;
default_type application/octet-stream;
client_max_body_size 10m;
....
}
Possibly Related Posts
Tuesday, 12 July 2011
How to hide query string in url with a .htaccess file
To masquerade the query string into a pretty SEO url you can use Apache's mod_rewrite.
Rewrite rules don't actually hide the query string, rewrite rules pretty much convert SEO friendly urls into the actual query string.
Example .htaccess:
url reads: yoursite.com/test.html
apache interprets as: yoursite.com/viewPage.php?ID=test
Therefore the following PHP code:
What if we want to pass more than one value, like "yoursite.com/viewPage.php?ID=test&category=coding" ?
We just have to convert /categories/coding/test.html into /viewPage.php?category=coding&ID=test
This will do the trick:
Rewrite rules don't actually hide the query string, rewrite rules pretty much convert SEO friendly urls into the actual query string.
Example .htaccess:
RewriteEngine onThe above rewrite rule will allow you to do something like this:
RewriteRule ([a-zA-Z0-9_]+)\.html$ viewPage.php?ID=$1 [L]
url reads: yoursite.com/test.html
apache interprets as: yoursite.com/viewPage.php?ID=test
Therefore the following PHP code:
<?phpwill output test.
$id=$_GET['ID'];
echo $id;
?>
What if we want to pass more than one value, like "yoursite.com/viewPage.php?ID=test&category=coding" ?
We just have to convert /categories/coding/test.html into /viewPage.php?category=coding&ID=test
This will do the trick:
RewriteEngine On
RewriteRule ^categories/(\w+)/(\w+)\.html viewPage.php?category=$1&ID=$2 [L]
Possibly Related Posts
Subscribe to:
Comments (Atom)