Apache上的反向代理(用于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)

除了激活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. 虚拟主机连接到给定的外部站点(如谷歌)[信用到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>
    

然而,这些虚拟主机都不起作用(我有连接故障或无休止加载)。

有人能帮我复习一下代码吗?

提前非常感谢!

以下是答案:

  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中的谷歌)

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

相关内容

  • 没有找到相关文章

最新更新