简体   繁体   English

Apache VirtualHost和反向代理无法在非特权端口中工作

[英]Apache virtualhost and reverse proxy not working in unprivileged port

I have an apache 2.2.15 webserver running in a RedHat 6.4 host for which I have limited privileges. 我有一个在RedHat 6.4主机中运行的apache 2.2.15 Web服务器,但我对此权限有限。

I have an httpd instance running in a directory owned by me. 我有一个httpd实例在我拥有的目录中运行。 This instance has its own etc, logs, htdocs, conf ,etcetera and symbolic links to the main Apache bin and modules. 该实例具有自己的etc,日志,htdocs,conf等,以及指向主要Apache bin和模块的符号链接。

The DNS guy has arranged myinstance.example.com to point to the server's ip address. DNS家伙已安排myinstance.example.com指向服务器的IP地址。

I also have configured VirtualHosts in my httpd.conf because in the future I might need more than one instance running in this server. 我还在httpd.conf中配置了VirtualHosts,因为将来我可能需要在此服务器上运行多个实例。

The Listen directive in my VirtualHost's htttpd.conf is set to port 8081, so if I go to myinstance.example.com:8081 the index.html in VirtualHost's htdocs is displayed in my browser. 我的VirtualHost的htttpd.conf中的Listen指令设置为端口8081,因此,如果我转到myinstance.example.com:8081,则会在浏览器中显示VirtualHost的htdocs中的index.html。

What I'd like to do now, is to "remove" the port number from the url and have myinstance.example.com to resolve to the VirtualHost in 8081. 我现在想做的是从URL中“删除”端口号,并让myinstance.example.com解析为8081中的VirtualHost。

I added the following block at the end of the VirtualHost's httpd.conf 我在VirtualHost的httpd.conf末尾添加了以下代码块

<VirtualHost *:8081>
    ServerAdmin me@myemailaddress.com
    DocumentRoot /apps/LAMP/dev/appname/hostname/htdocs
    ServerName myinstance.example.com
    ProxyPreserveHost On
    ProxyPass / myinstance.example.com:8081/
    ProxyPassReverse / http://myinstance.example.com:8081/
    ErrorLog logs/error.log
    CustomLog logs/access.log common
</VirtualHost>

and in the same file, these lines are present too: 在同一文件中,也存在以下几行:

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
.
.
.
ProxyRequests Off
ProxyVia On
ProxyPreserveHost On

I start my Apache instance using: 我使用以下命令启动我的Apache实例:

/usr/sbin/httpd -d /apps/LAMP/dev/appname/hostname -DPHP5 -f /apps/LAMP/dev/appname/hostname/etc/httpd.conf

When I point in my firefox browser to myinstance.example.org (without port number) I get "Unable to connect error" and the latest entries in error.log don't seem to be related to the issue. 当我在Firefox浏览器中指向myinstance.example.org(无端口号)时,出现“无法连接错误”,并且error.log中的最新条目似乎与该问题无关。

[Tue Oct 07 13:59:28 2014] [error] (2)No such file or directory: mod_mime_magic: can't read magic file /apps/LAMP/dev/appname/hostname/conf/magic
[Tue Oct 07 13:59:28 2014] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Oct 07 13:59:28 2014] [error] (2)No such file or directory: mod_mime_magic: can't read magic file /apps/LAMP/dev/appname/hostname/conf/magic
[Tue Oct 07 13:59:28 2014] [notice] Digest: generating secret for digest authentication ...
[Tue Oct 07 13:59:28 2014] [notice] Digest: done
[Tue Oct 07 13:59:28 2014] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations
[Tue Oct 07 13:59:51 2014] [error] server reached MaxClients setting, consider raising the MaxClients setting

Any idea on what I may be doing wrong? 对我可能做错的事情有任何想法吗? Any suggestion? 有什么建议吗?

First of all I would get rid of all the errors. 首先,我将摆脱所有错误。 The one that caught my attention and it might be a show stopper is this one: 一个引起我注意并且可能是表演停止的人是这个:

[error] server reached MaxClients setting

consider raising the MaxClients setting 考虑提高MaxClients设置

It got fixed by using the main Apache instance in port 80 acting as the reverse proxy. 通过使用端口80中的主要Apache实例作为反向代理来解决此问题。

I added this at the end of /etc/httpd/conf/httpd.conf 我在/etc/httpd/conf/httpd.conf的末尾添加了这个

#Using host ip address
<VirtualHost 10.18.1.20:80>    
    ServerAdmin me@example.com
    #DocumentRoot /apps/LAMP/dev/appname/hostname/htdocs
    ServerName myinstance.example.com
    ProxyPreserveHost On
    ProxyPass / http://myinstance.example.com:8081/
    ProxyPassReverse / http://myinstance.example.com:8081/
    ErrorLog logs/error.log
    CustomLog logs/access.log common
</VirtualHost>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM