Gospel. Culture. Technology. Music.

Tag: Proxy


OpenVPN Sharing a TCP Port with SSL on NGINX and Apache?

I’m absolutely baffled there isn’t more information out there about this. It seems like web managers and techs would be all over this, but there’s barely any information out there on this. I had a hard time finding documentation on OpenVPN’s site itself!

As one guy stated here (the post where I finally understood how this works) it’s not really “sharing” the port per se, but OpenVPN is deciphering between HTTP/S traffic and OpenVPN traffic and then forwarding web traffic over to another port, defined below. That’s crucial to understand.

Before I start, I want to note this doesn’t have to be done on an SSL port, as I understand it. I’m just using that as an example because it seems to be the most logical way to make it work if this is your configuration (you know, an SSL VPN going to an SSL port).

It should also be noted in this configuration example that OpenVPN, using the port-share parameter, is actually doing the listening on TCP port 443 and acting as a proxy itself that forwards non-OpenVPN traffic to the NGINX SSL port which we’ll layout below. You cannot do this utilizing UDP, that I know of.

So here’s what you do.

1) Set your NGINX or Apache listening ports. Set your NGINX standard http port 80 and SSL listening port to something OTHER than 443 … so, for arguments’ sake, let’s set it to 4443.

So it would look like this for Apache and NGINX:

For Apache, in the main httpd.conf (Windows) or in ports.conf (Ubuntu/Linux):

Listen 4443

For NGINX, in /etc/nginx/sites-available/defaults:

server {
        listen   4443;

        location / {
                root  /web/etc/blah;
        }
}

Once implemented, restart your respective service, Apache or NGINX.

2) Next, you’re going to set your OpenVPN server parameters. Set your listening port to 443 from its standard 1194 and add the port-share parameter to point to the Apache or NGINX port created above. The config should look as follows now:

port 443
port-share 127.0.0.1 4443
proto tcp

OpenVPN will now be ready to accept connections over 443 and route the appropriate https/SSL traffic to Apache or NGINX.

3) Change your firewall settings. Leave your TCP port 80 rule pointing directly to Apache or NGINX. Then point your SSL rule to TCP port 443 running on your OpenVPN server. OpenVPN will now catch the traffic directed at it and decipher between OpenVPN traffic and HTTPS traffic.

4) Change the configuration in your OpenVPN clients. Point your OpenVPN clients to TCP port 443 instead of the port you were using before:

remote domain.name.com 443

or

remote [IP ADDRESS] 443

Hope it works. Cheers!

PHP Code for Remote IP Address Detection on a Web Page

I wrote this code today to return the IP address of a remote host when either the host hits the web server directly or accesses it through a web proxy (as in my situation). Thought someone might find it useful.

function writeIPAddress() {
if (isset($_SERVER[‘HTTP_X_FORWARDED_FOR’]) == ”) {
return $_SERVER[‘REMOTE_ADDR’];
}

else {
return $_SERVER[‘HTTP_X_FORWARDED_FOR’];
}
}

Then, if you want to return the IP address as text on the page, simply do this:

echo writeIPAddress();

In addition, if you want to return the reverse DNS address of the IP, do this:

echo @gethostbyaddr(writeIPAddress());

Apache Web Server Setup as a Reverse Web Proxy

Well, I’ve finally changed up my website architecture using Apache 2.0.55 to where it essentially looks like this: client browser connects to HTTP port 80 (or HTTPS port 443) through the internet to the outside of my firewall > the firewall NATs the connection to the web proxy ports (undisclosed) > the web proxy connects to one of several internal web servers I’ve specified it to connect to > the queried web server then renders the page back through the web proxy and then back to the client through the internet. Basically, with this new design in place, I can offload SSL processes to the web proxy (separate server) and it will take the encryption load off of my web servers (thus making it much more efficient on processing). I can also proxy any internal network appliance web interface (such as SHOUTCast servers, webcam servers, wireless access point servers, etc.) through the web proxy, and on top of that I can encrypt it all using AES-256 (when using Firefox), as well as password out specific sites at the Apache web server level. Some really sweet technology …

Powered by WordPress & Theme by Anders Norén