代理,Apache,Tomcat – VHosts

我有一个设置如下:

互联网 – 路由器 – [DMZ] – pfsense – networking服务器

router = jenky塑料廉价o路由器(我好mikrotik /路由板死亡)。 将pfsense的ip地址设置为DMZ。

pfsense =做基本防火墙加代理/反向代理。 代理服务器用于将URL转发到防火墙后面正确的networking服务器。

webserver =运行httpd(apache)和tomcat6(分别安装,从yum,但在不同的时间,所以它不是Apache + Tomcat的东西)的Centos框。

几个网站从这个特定的networking服务器运行,由Apache的虚拟主机处理。

 ex: http://www.somesite.com, http://www.mysite.com, etc 

Tomcat在扩展名为/ mywebapp的端口8080上运行应用程序。

 ex: http://www.somesite.com:8080/mywebapp 

我已经在pfsense正确configuration了所有的东西,把Apache服务的网站的所有子域转发给正确的主机。

我configuration了/etc/httpd/conf/httpd.conf来包含虚拟主机configuration

 <VirtualHost *:80> ServerName mywebapp.somesite.com ProxyPass / http://www.somesite.com:8080/mywebapp ProxyPassReverse / http://www.somesite.com:8080/mywebapp ProxyRequests Off <Proxy http://www.somesite.com:8080/mywebapp*> Order deny,allow Allow from all </Proxy> ErrorLog logs/mywebapp.somesite.com-error_log CustomLog logs/mywebapp.somesite.com-access_log common </VirtualHost> 

我已经修改了我的tomcat6 server.xml文件,并更改了第一个连接器以包含proxyNameproxyPort

 <!-- A "Connector" represents an endpoint by which requests are received and responses are returned. Documentation at : Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) Java AJP Connector: /docs/config/ajp.html APR (HTTP/AJP) Connector: /docs/apr.html Define a non-SSL HTTP/1.1 Connector on port 8080 --> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" proxyName="mywebapp.somesite.com" proxyPort="8080" redirectPort="8443" URIEncoding="UTF-8"/> 

无论我尝试什么,当我将mywebapp.somesite.com放入浏览器时,它会redirect到mywebapp.somesite.com:8080/mywebapp

当我想访问它作为mywebapp.somesite.com ,并保持在浏览器的地址栏。 这将使url发布更友好等。

我已经在mywebapp DNSconfiguration了CNAME

www.somesite.com不受此影响。

httpd日志是正常的… tomcat6的日志什么都不显示。 我知道请求打在正确的盒子,因为www.somesite.com:8080/mywebapp (与其他网站一起)的作品。

iptables被禁用,所以如果SELinux

我究竟做错了什么? 请指教。

UPDATE:我尝试添加ProxyPreserveHost On虚拟主机configuration每一个评论,但没有骰子。 当这一行被添加,并且apache和tomcat都重新启动时,我无法访问mywebapp.somesite.comwww.somesite.com:8080/mywebapp 。 基本上添加这个configuration使mywebapp根本不可访问,但是我知道它仍在运行。

UPDATE 2:添加从服务器获取的tcpdump。 我正在显示第一个连接,因为它正在从pfsense (代理)传递到webserver

 192.168.0.1 == pfsense 192.168.1.1 == webserver 192.168.2.1 == "internet" 192.168.0.1 > 192.168.1.1 GET / HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0) Accept-Encoding: gzip, deflate Host: mywebapp.somesite.com DNT: 1 Via: 1.1 proxy.somecompany.com (squid/3.1.20) X-Forwarded-For: 192.168.2.1 Cache-Control: max-age=259200 192.168.1.1 > 192.168.2.1 GET /mywebapp HTTP/1.1 Host: www.somesite.com:8080 Accept: text/html, application/xhtml+xml, */* Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0) Accept-Encoding: gzip, deflate DNT: 1 Via: 1.1 proxy.somecompany.com (squid/3.1.20) X-Forwarded-For: 192.168.2.1, 192.168.0.1 Cache-Control: max-age=259200 X-Forwarded-Host: mywebapp.somesite.com X-Forwarded-Server: mywebapp.somesite.com Connection: Keep-Alive 192.168.2.1 > 192.168.1.1 GET /mywebapp HTTP/1.1 Host: www.somesite.com:8080 Accept: text/html, application/xhtml+xml, */* Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0) Accept-Encoding: gzip, deflate DNT: 1 Via: 1.1 proxy.somecompany.com (squid/3.1.20) X-Forwarded-For: 192.168.2.1, 192.168.0.1 Cache-Control: max-age=259200 X-Forwarded-Host: mywebapp.somesite.com X-Forwarded-Server: mywebapp.somesite.com Connection: Keep-Alive 192.168.1.1 > 192.168.2.1 HTTP/1.1 302 Moved Temporarily Server: Apache-Coyote/1.1 Location: http://mywebapp.somesite.com:8080/mywebapp/ Content-Length: 0 Date: Thu, 04 Apr 2013 05:14:44 GMT 192.168.2.1 > 192.168.1.1 HTTP/1.1 302 Moved Temporarily Server: Apache-Coyote/1.1 Location: http://mywebapp.somesite.com:8080/mywebapp/ Content-Length: 0 Date: Thu, 04 Apr 2013 05:14:44 GMT 192.168.1.1 > 192.168.0.1 HTTP/1.1 302 Moved Temporarily Date: Thu, 04 Apr 2013 05:14:44 GMT Server: Apache-Coyote/1.1 Location: http://mywebapp.somesite.com:8080/mywebapp/ Content-Length: 0 Connection: close Content-Type: text/plain; charset=UTF-8 192.168.2.1 > 192.168.1.1 GET /mywebapp/ HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0) Accept-Encoding: gzip, deflate DNT: 1 Connection: Keep-Alive Host: mywebapp.somesite.com:8080 192.168.1.1 > 192.168.2.1 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Encoding: gzip Expires: 0 Cache-Control: no-cache,must-revalidate X-App-Theme: default Set-Cookie: JSESSIONID=81CE83D61454A8E75C222759FA118338; Path=/mywebapp X-App: 1.395 X-App2: 1.508 X-App2-Session: e797c95b X-App-CLI-Port: 36143 X-App2-CLI-Port: 36143 X-App2-CLI2-Port: 36143 X-Instance-Identity: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjEfz8W2LiYRfrJQYH35uwtgQBpy0g6bTvBaTuARRpVLUmi+lnEfD/nVJY4GJoSfGzgnJAQ3MSqX+e1F4y2Jg5hwa2L0jibpb//BbfIMZkYZk8CtLMrkGvLC1nB7sghXupWOUOhWnzFq+a+LHSANNqfaMs9k6xJI6rvwIDAQAB Content-Type: text/html;charset=UTF-8 Content-Length: 3879 Date: Thu, 04 Apr 2013 05:14:44 GMT 192.168.2.1 > 192.168.1.1 GET /mywebapp/static/e797c95b/css/style.css HTTP/1.1 Accept: text/css Referer: http://mywebapp.somesite.com:8080/mywebapp/ Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0) Accept-Encoding: gzip, deflate Host: mywebapp.somesite.com:8080 DNT: 1 Connection: Keep-Alive Cookie: JSESSIONID=81CE83D61454A8E75C222759FA118338 192.168.1.1 > 192.168.2.1 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Last-Modified: Mon, 25 Mar 2013 20:17:34 GMT Expires: Fri, 04 Apr 2014 05:14:44 GMT Accept-Ranges: bytes Content-Encoding: gzip Content-Type: text/css Content-Length: 5763 Date: Thu, 04 Apr 2013 05:14:44 GMT 192.168.2.1 > 192.168.1.1 GET /mywebapp/static/e797c95b/css/color.css HTTP/1.1 Accept: text/css Referer: http://mywebapp.somesite.com:8080/mywebapp/ Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0) Accept-Encoding: gzip, deflate Host: mywebapp.somesite.com:8080 DNT: 1 Connection: Keep-Alive Cookie: JSESSIONID=81CE83D61454A8E75C222759FA118338 

我粗略地解释为:

浏览器(互联网) – >请求命中路由器 – >通过DMZ – >命中pfsense …

pfsense> webserver:呃,这是这个HTTP请求…对于mywebapp.somesite.com? 我们知道一个mywebapp.somesite.com吗?

互联网: Sup,我听说你正在寻找一些HTTP? 我有一些mywebapp.somesite.com。

互联网>networking服务器:雅,我头上你。 给我一些dat mywebapp.somesite.com。

networking服务器:哈,开个玩笑,伙计。 我真的有一些mywebapp.somesite.com:8080/mywebapp,你挖?

互联网>networking服务器:跆拳道? 你是认真的吗!?

网站服务器> pfsense:老兄,我告诉过你,我们需要更多的mywebapp.somesite.com,这家伙很生气!

互联网>networking服务器:嗯…好吧,只要给我什么你得到了mywebapp.somesite.com:8080/mywebapp。 我挖。

networking服务器>互联网:唷! 如果你挖,我挖…你挖? 这里有一些HTTP。

互联网>networking服务器:啊,现在我们在说话。 再引用Referer的/mywebapp/static/…/style.css:http://mywebapp.somesite.com:8080/mywebapp

networking服务器>互联网:把它放在我的男人,把它全部。这一切都OK。

互联网>networking服务器:好吧,给予更多的/mywebapp/static/…/color.css从Referer: http ://mywebapp.somesite.com:8080/mywebapp

等等等等…

Update 3:添加我的当前/etc/httpd/conf/httpd.conf文件以显示更新/更改到目前为止。

 <VirtualHost *:80> ServerName mywebapp.somesite.com ProxyPass / http://www.somesite.com:8080/mywebapp/ ProxyPassReverse / http://www.somesite.com:8080/mywebapp/ ProxyRequests off RewriteEngine on RewriteRule ^(/.*) http://www.somesite.com:8080/mywebapp/$1 [P] # ProxyPreserveHost On <Proxy http://www.somesite.com:8080/mywebapp*> Order deny,allow Allow from all </Proxy> ErrorLog logs/mywebapp.somesite.com-error_log CustomLog logs/mywebapp.somesite.com-access_log common </VirtualHost> 

目前没有一个可用于testing的框,但是您所看到的是来自tomcat的302redirect。 如果您请求不带尾随斜杠的目录索引,总会发生这种情况。

尝试以下ProxyPass和ProxyPassReverseconfiguration:

 ProxyPass / http://www.somesite.com:8080/mywebapp/ ProxyPassReverse / http://www.somesite.com:8080/mywebapp/ 

注意尾部的斜杠。 这应该避免302临时redirect。

编辑:对于静态的东西,尝试添加:

 RewriteEngine on RewriteRule ^(/.*) http://www.somesite.com:8080/mywebapp/$1 [P] 

这基本上说,采取从您的Web服务器的根源的每个请求,并交给代理模块。

为什么你需要Proxy部分?

 <Proxy http://www.somesite.com:8080/mywebapp*> Order deny,allow Allow from all </Proxy> 

似乎redirect是从Tomcat一方生成的URL。

尝试添加ProxyPreserveHost On您的<VirtualHost *:80>configuration?