我已经build立了wiki软件Gitit在同一个Apache服务器(端口1848和4000)的两个独立的端口上运行。 我已经确认他们正在运行。
现在我想代理这两个网站更漂亮的url,如sitea.com和siteb.com。 两者的IP地址是相同的(比如12.34.56.78)。
我的服务器pipe理员已经添加了名称的DNS条目,但我似乎无法让我的Apacheconfiguration工作。 按照这里的说明 ,我试图build立一个像这样的VirtualHost:
NameVirtualHost *:1848 <VirtualHost *:1848> ServerName sitea.com DocumentRoot /var/www/ RewriteEngine On ProxyPreserveHost On ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPassReverse / http://127.0.0.1:1848 RewriteRule ^(.*) http://127.0.0.1:1848$1 [P] ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined ServerSignature On </VirtualHost>
而另一个类似的虚拟主机的另一端口4000.但是,当我然后发出service httpd restart ,我得到一个FAILED消息,当启动httpd,我的浏览器无法连接到sitea.com。
据我所知,我的httpd.conf的其余部分是分配的默认文件。 我的服务器正在RedHat Enterprise机器上运行。 我是Apache的新手,所以我确信这里有一个明显的答案,但在尝试对configuration进行各种调整后,我无法弄清楚我做错了什么。
编辑:问题是,我没有检查,以确保我的错误日志的path名是正确的。 我的发行版存储日志/ var / log / httpd而不是/ var / log / apache2。 (脸红)。
NameVirtualHost *:80 <VirtualHost *:80> ServerName www.domain.tld ServerAlias domain.tld *.domain.tld DocumentRoot /www/domain </VirtualHost> <VirtualHost *:80> ServerName www.otherdomain.tld DocumentRoot /www/otherdomain </VirtualHost>
这个例子是从虚拟主机的Apache文档 。 在每个<VirtualHost/>块中定义您的反向代理设置。
以下configuration可能会有所帮助
NameVirtualHost *:80 <VirtualHost *:80> ServerName sitea.com DocumentRoot /var/www/ RewriteEngine On ProxyPreserveHost On ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://127.0.0.1:1848/ ProxyPassReverse / http://127.0.0.1:1848/ ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined ServerSignature On </VirtualHost> <VirtualHost *:80> ServerName siteb.com DocumentRoot /var/www/ RewriteEngine On ProxyPreserveHost On ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://127.0.0.1:4000/ ProxyPassReverse / http://127.0.0.1:4000/ ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined ServerSignature On </VirtualHost>
不好意思说这个,但问题是我的错误日志的path是错误的。 我的发行版将错误日志放在/ var / log / httpd中,所以Apache每次进入ErrorLog行时都会因为没有这样的目录而窒息。 活到老,学到老 …