You have a web app on another server that is running on the same ports as the primary web server (QNAP) to which the requests are being forwarded but you would like to access that application from the WAN side.
[Problem Description]
Port forwarding on a NAT enabled router will only allow to forward requests of the same port to a single IP address within your LAN. To overcome this problem this method can be used to let the QNAP webserver act as a proxy for another application.
[Caveat]
This howto does not handle the security of the target web application you will be proxying.
[Setting up virtual hosts manually]
While the QNAP offers virtual host support from the GUI, it lacks customization. Therefore I suggest using this fine HOWTO; http://forum.qnap.com/viewtopic.php?f=32&t=14450
[Adding mod_proxy support]
Open a terminal session to your QNAP or use a tool like WinSCP to edit your /etc/config/apache/apache.conf file. Just before the custom vhost include you created before add the following line;
Code: Select all
/etc/config/apache/extra/httpd-proxy.conf
Now create the /etc/config/apache/extra/httpd-proxy.conf and add the following to it;
Code: Select all
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
[Editing your virtual host (suffix method)]
Edit your customized.conf file you have created using the virtual host HOWTO
Add the proxy section and ProxyPass/ProxyPassReverse directives as shown below;
Code: Select all
<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias domain.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /myapp http://otherserver/myapp
ProxyPassReverse /myapp http://otherserver/myapp
DocumentRoot "/share/Qweb/vhosts/mydomain.com/htdocs"
<Directory "/share/Qweb/vhosts/mydomain.com/htdocs">
Options FollowSymLinks Multiviews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This method will create access to the app via http://www.mydomain.com/myapp
[Editing your virtual host (sub-domain method)]
Alternatively you can use this method if you prefer to access your app via a DNS sub-domain. I have optionally added ports on this example, while they are not needed they are there as an example to show port redirection. In this particular instance tcp/7000 will be redirected to the default tcp/80 for http.
Again, edit your custom.conf
Code: Select all
<VirtualHost *:80>
ServerName myapp.mydomain.com
ServerAlias myapp.mydomain.com
ProxyRequests Off
ProxyVia Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://otherserver:7000/
ProxyPassReverse / http://otherserver:7000/
</VirtualHost>
This method will create access to the app via http://myapp.mydomain.com
[Restarting Apache]
To get things working you now need to either restart the Apache web server from the QNAP GUI or issue the following command from a terminal session;
Code: Select all
/etc/init.d/Qthttpd.sh restart
You are now done and should be able to access your app via the Apache proxy on your QNAP.
Please feel free to comment and/or make suggestions to improve.
Enjoy,
fork