Apache上的反向代理(针对QNAP)

时间:2015-11-17 17:40:54

标签: apache ssl proxy dns qnap

由于我无法访问80和443以外的端口,我想在QNAP上使用Apache访问一些资源。

特别是我想:

  1. 设置虚拟主机(使用sub1.domain.com)连接到同一主机上运行的服务(我的QNAP)(http://localhost:58000
  2. 设置虚拟主机(使用sub2.domain.com)连接到局域网内的其他主机(http://192.168.1.1:78080
  3. 设置虚拟主机(使用sub3.domain.com)连接外部网站(例如https://www.google.com
  4. 除了激活proxy_module和proxy_ssl_module(并相应地更改DNS)之外,我还想在httpd-vhosts-user.conf(对于1.和2.)以及httpd-ssl-vhosts-user上使用以下行代码。 conf(3。):

    一般部分(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. 虚拟主机,用于连接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. 虚拟主机,用于连接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. 虚拟主机连接到指定的外部网站(例如谷歌)[信用额度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>
      
    4. 但是这些虚拟主机都不起作用(我有连接失败或无休止加载)。

      有人可以帮我查一下代码吗?

      非常感谢你!

1 个答案:

答案 0 :(得分:1)

以下是答案:

  1. 虚拟主机,用于连接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. 虚拟主机,用于连接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. 虚拟主机连接到指定的外部网站(例如,仅限HTTP的Google)

    <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>