1

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.

In particular I would like to:

  1. set a Virtual Host (using sub1.domain.com) to connect to a service running on the same host (my QNAP) (http://localhost:58000)
  2. set a Virtual Host (using sub2.domain.com) to connect to another host within the LAN (http://192.168.1.1:78080)
  3. set a Virtual Host (using sub3.domain.com) to connect to an external website (e.g. https://www.google.com)

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.):

General sections (FYI):

/etc/config/apache/extra/httpd-vhosts-user.conf

    NameVirtualHost *:80

    <VirtualHost _default_:80>
       DocumentRoot "/share/Web"
    </VirtualHost>

/etc/config/apache/extra/httpd-ssl-vhosts-user.conf

    NameVirtualHost *:443

    <VirtualHost _default_:443>
       DocumentRoot "/share/Web"
    </VirtualHost>
  1. Virtual Host to connect to the service running on http://localhost:58000

    <VirtualHost *:80>
       ServerName sub1.domain.com
       DocumentRoot "/share/Web/sub1"
    
       ProxyPreserveHost On 
       ProxyRequests Off 
       ProxyVia Off 
        ProxyPass /sub1 http://localhost:58000
        ProxyHTMLURLMap http://localhost:58000 /sub1
    
       <Location /sub1>
          ProxyPassReverse /
          ProxyHTMLInterp On
          ProxyHTMLURLMap  /      /sub1
          RequestHeader    unset  Accept-Encoding
       </Location>
    
       <Proxy *>
          AddDefaultCharset off
          Order deny,allow
          Deny from all
          Allow from all
       </Proxy>
    
       <Directory "/share/Web/sub1">
          Options FollowSymLinks MultiViews 
          Order allow,deny 
          Allow from all
       </Directory>   
    </VirtualHost>
    
  2. Virtual Host to connect to other service running on http://192.168.1.1:78080

    <VirtualHost *:80>
       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
    
       <Location /Asus>
          ProxyPassReverse /
          ProxyHTMLInterp On
          ProxyHTMLURLMap  /      /sub2
          RequestHeader    unset  Accept-Encoding
       </Location>
    
       <Proxy *>
          AddDefaultCharset off
          Order deny,allow
          Deny from all
          Allow from all
       </Proxy>
    
       <Directory "/share/Web/sub2">
          Options FollowSymLinks MultiViews 
          Order allow,deny 
          Allow from all
       </Directory>
    </VirtualHost>
    
  3. Virtual Host to connect to the given external site (e.g. google) [credits to kamal @ serverfault.com]

    <VirtualHost *:443>
       ServerName sub3.domain.com
    
       ProxyPreserveHost On
    
       <Proxy *>
          AddDefaultCharset off
          Order deny,allow
          Deny from all
          Allow from all
       </Proxy>
    
        ProxyPass /sub3 https://www.google.com/
        ProxyHTMLURLMap https://www.google.com /sub3
    
       <Location /sub3>
          ProxyPassReverse /
          ProxyHTMLInterp On
          ProxyHTMLURLMap  /      /sub3
          RequestHeader    unset  Accept-Encoding
       </Location>
    </VirtualHost>
    

However none of these Virtual Hosts work (I have a connection fail or endless loading).

Could someone please help me reviewing the code?

Thank you very much in advance!

Community
  • 1
  • 1
giopas
  • 645
  • 1
  • 6
  • 10

1 Answers1

1

Here are the answers:

  1. Virtual Host to connect to the service running on http://localhost:58000

    <VirtualHost *:80>
    ServerName sub1.domain.com
    ProxyRequests Off
    <Proxy *>
    Order deny,allow
    Allow from all
    </Proxy>
    <Location />
    Order allow,deny
    Allow from all
    </Location>
    ProxyPreserveHost On
    ProxyPass / http://localhost:58000/
    ProxyPassReverse / http://localhost:58000/
    ProxyStatus On
    </VirtualHost>
    
  2. Virtual Host to connect to other service running on http://192.168.1.1:78080

    <VirtualHost *:80>
    ServerName sub2.domain.com
    ProxyRequests Off
    <Proxy *>
    Order deny,allow
    Allow from all
    </Proxy>
    <Location />
    Order allow,deny
    Allow from all
    </Location> 
    ProxyPreserveHost On
    ProxyPass / http://192.168.1.1:78080/
    ProxyPassReverse / http://192.168.1.1:78080/
    ProxyStatus On
    </VirtualHost>
    
  3. Virtual Host to connect to the given external site (e.g. google in HTTP only)

    <VirtualHost *:80>
    ServerName sub3.domain.com
    DocumentRoot "/share/Web"
    <Directory "/share/Web">
    Options Indexes Includes FollowSymLinks
    AllowOverride All
    Order Allow,Deny
    Allow from all
    Deny from none
    </Directory>
    <Location />
    ProxyPass http://google.com/
    ProxyPassReverse http://google.com/
    </Location>
    </Virtualhost>
    
giopas
  • 645
  • 1
  • 6
  • 10