【问题标题】:Apache VirtualHost proxyApache VirtualHost 代理
【发布时间】:2018-01-15 20:19:35
【问题描述】:

我正在通过互联网寻找解决我的问题的方法。我找到了一些,研究了 apache 虚拟主机文档,但没有成功解决这个问题。也许是我理解错了,或者只是我很笨……

我有 2 个域,比如说 www.example1.com、www.example2.com 两者都指向 IP 111.222.333.444 上的同一台服务器

在这台服务器上,我有两个应用程序,在 (localhost) 8080 和 8090 上。 我想把 www.example1.com 代理到 8080,把 www.example2.com 代理到 8090。

我阅读了 apache 虚拟主机文档并在/etc/apache2/sites-enabled/000-default.conf 中添加了一些内容,现在看起来像这样

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName www.example1.com
    ServerAlias example1.com
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>
<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName www.example2.com
    ServerAlias example2.com
    ProxyPass / http://localhost:8090/
    ProxyPassReverse / http://localhost:8090/
</VirtualHost>

现在当我输入 www.example1.com 时,我得到的是 apache 默认页面,与 www.example2.com 相同。当我将第一个虚拟主机(apache 默认)更改为端口 f.e 81 时,我收到 500 错误:

内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。 请通过 [no address given] 联系服务器管理员,告知他们此错误发生的时间,以及您在此错误之前执行的操作。 服务器错误日志中可能提供有关此错误的更多信息。

我在这里做错了什么?

【问题讨论】:

    标签: apache proxy virtualhost


    【解决方案1】:

    看在上帝的份上,这个配置一切正常……挖又挖,我找到了“解决方案”here。我只缺少proxy_balancer mod。在其他指南和 stackoverflow 问题中,只提到了 proxy 和 proxy_http 模式。

    【讨论】:

      猜你喜欢
      • 2018-09-08
      • 2013-08-12
      • 2015-03-04
      • 1970-01-01
      • 2016-08-08
      • 1970-01-01
      • 2017-02-17
      • 2020-02-06
      • 2011-10-21
      相关资源
      最近更新 更多