title: Reverse proxy on Apache (for QNAP)
body: <p>As I cannot access to ports other than 80 and 443 at work, I would like to make accessible some resources using Apache on my QNAP.</p>
  
  <p>In particular I would like to:</p>
  
  <ol>
  <li>set a Virtual Host (using sub1.domain.com) to connect to a service running on the same host (my QNAP) (<a href="http://localhost:58000" rel="nofollow noreferrer">http://localhost:58000</a>)</li>
  <li>set a Virtual Host (using sub2.domain.com) to connect to another host within the LAN (<a href="http://192.168.1.1:78080" rel="nofollow noreferrer">http://192.168.1.1:78080</a>)</li>
  <li>set a Virtual Host (using sub3.domain.com) to connect to an external website (e.g. <a href="https://www.google.com" rel="nofollow noreferrer">https://www.google.com</a>)</li>
  </ol>
  
  <p>Beside activating proxy_module and proxy_ssl_module (and changing DNS accordingly), I have thought to use the following line codes on httpd-vhosts-user.conf (for 1. and 2.) and on httpd-ssl-vhosts-user.conf (for 3.):</p>
  
  <p>General sections (FYI):</p>
  
  <p>/etc/config/apache/extra/httpd-vhosts-user.conf</p>
  
  <pre><code>    NameVirtualHost *:80
  
      &lt;VirtualHost _default_:80&gt;
         DocumentRoot "/share/Web"
      &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>/etc/config/apache/extra/httpd-ssl-vhosts-user.conf</p>
  
  <pre><code>    NameVirtualHost *:443
  
      &lt;VirtualHost _default_:443&gt;
         DocumentRoot "/share/Web"
      &lt;/VirtualHost&gt;
  </code></pre>
  
  <ol>
  <li><p>Virtual Host to connect to the service running on <a href="http://localhost:58000" rel="nofollow noreferrer">http://localhost:58000</a></p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
     ServerName sub1.domain.com
     DocumentRoot "/share/Web/sub1"
  
     ProxyPreserveHost On 
     ProxyRequests Off 
     ProxyVia Off 
      ProxyPass /sub1 http://localhost:58000
      ProxyHTMLURLMap http://localhost:58000 /sub1
  
     &lt;Location /sub1&gt;
        ProxyPassReverse /
        ProxyHTMLInterp On
        ProxyHTMLURLMap  /      /sub1
        RequestHeader    unset  Accept-Encoding
     &lt;/Location&gt;
  
     &lt;Proxy *&gt;
        AddDefaultCharset off
        Order deny,allow
        Deny from all
        Allow from all
     &lt;/Proxy&gt;
  
     &lt;Directory "/share/Web/sub1"&gt;
        Options FollowSymLinks MultiViews 
        Order allow,deny 
        Allow from all
     &lt;/Directory&gt;   
  &lt;/VirtualHost&gt;
  </code></pre></li>
  <li><p>Virtual Host to connect to other service running on <a href="http://192.168.1.1:78080" rel="nofollow noreferrer">http://192.168.1.1:78080</a></p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
     ServerName sub2.domain.com
     DocumentRoot "/share/Web/sub2"
  
     ProxyPreserveHost On 
     ProxyRequests Off 
     ProxyVia Off 
     ProxyPass /sub2 http://192.168.1.1:78080
     ProxyHTMLURLMap http://192.168.1.1:78080 /sub2
  
     &lt;Location /Asus&gt;
        ProxyPassReverse /
        ProxyHTMLInterp On
        ProxyHTMLURLMap  /      /sub2
        RequestHeader    unset  Accept-Encoding
     &lt;/Location&gt;
  
     &lt;Proxy *&gt;
        AddDefaultCharset off
        Order deny,allow
        Deny from all
        Allow from all
     &lt;/Proxy&gt;
  
     &lt;Directory "/share/Web/sub2"&gt;
        Options FollowSymLinks MultiViews 
        Order allow,deny 
        Allow from all
     &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre></li>
  <li><p>Virtual Host to connect to the given external site (e.g. google) [credits to <a href="https://serverfault.com/questions/295968/when-using-reverse-proxy-backend-server-does-301-back-to-the-proxy-server-or-ch">kamal @ serverfault.com</a>]</p>
  
  <pre><code>&lt;VirtualHost *:443&gt;
     ServerName sub3.domain.com
  
     ProxyPreserveHost On
  
     &lt;Proxy *&gt;
        AddDefaultCharset off
        Order deny,allow
        Deny from all
        Allow from all
     &lt;/Proxy&gt;
  
      ProxyPass /sub3 https://www.google.com/
      ProxyHTMLURLMap https://www.google.com /sub3
  
     &lt;Location /sub3&gt;
        ProxyPassReverse /
        ProxyHTMLInterp On
        ProxyHTMLURLMap  /      /sub3
        RequestHeader    unset  Accept-Encoding
     &lt;/Location&gt;
  &lt;/VirtualHost&gt;
  </code></pre></li>
  </ol>
  
  <p>However none of these Virtual Hosts work (I have a connection fail or endless loading).</p>
  
  <p>Could someone please help me reviewing the code?</p>
  
  <p>Thank you very much in advance!</p>