Apache VirtualHost代理

时间:2018-01-15 20:19:35

标签: apache proxy virtualhost

我一直在寻找通过互联网解决我的问题的方法。我找到了一些,研究过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错误:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

为了上帝的缘故,这个配置一切正常......挖掘和挖掘,我找到了解决方案&#34; here。我只缺少proxy_balancer mod。在其他指南和stackoverflow问题中,只提到了proxy和proxy_http模式。