1

由于我在工作中无法访问除 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

除了激活 proxy_module 和 proxy_ssl_module(并相应地更改 DNS)之外,我还考虑在 httpd-vhosts-user.conf (对于 1. 和 2.)和 httpd-ssl-vhosts-user.conf (对于3.):

一般部分(仅供参考):

/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. 虚拟主机连接到给定的外部站点(例如 google)[归功于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 回答 1

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>
    
于 2016-03-01T08:53:27.020 回答