gpt4 book ai didi

apache - Apache 上的反向代理(适用于 QNAP)

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:23 28 4
gpt4 key购买 nike

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

我特别想:

  1. 设置虚拟主机(使用 sub1.domain.com)以连接到在同一主机(我的 QNAP)上运行的服务 (http://localhost:58000)
  2. 设置虚拟主机(使用 sub2.domain.com)以连接到 LAN 中的另一台主机 (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>

关于apache - Apache 上的反向代理(适用于 QNAP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33763556/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com