Eu tenho uma configuração assim:
Internet -- router -[DMZ]- pfsense -- webserver
router =
jenky plástico barato-o roteador (meu bom mikrotik / routerboard morreu). Tem endereço IP do pfsense definido como DMZ.
pfsense =
fazendo o firewall básico mais o proxy / proxy reverso. Os proxies são para encaminhamento de URL para o servidor web correto por trás do firewall.
A caixa
webserver =
centos executando httpd (apache) e tomcat6 (instalados separadamente, ambos do yum, mas em momentos diferentes, portanto não é o apache + tomcat).
Vários sites são executados neste servidor específico, manipulados pelos hosts virtuais do apache.
ex: http://www.example.com, http://www.example1.com, etc
O Tomcat executa um aplicativo na porta 8080 na extensão / mywebapp.
ex: http://www.example.com:8080/mywebapp
Configurei tudo adequadamente em pfsense
para encaminhar todos os subdomínios dos sites servidos pelo apache para o host correto.
Eu configurei o /etc/httpd/conf/httpd.conf para incluir a configuração do host virtual como
<VirtualHost *:80>
ServerName mywebapp.example.com
ProxyPass / http://www.example.com:8080/mywebapp
ProxyPassReverse / http://www.example.com:8080/mywebapp
ProxyRequests Off
<Proxy http://www.example.com:8080/mywebapp*>
Order deny,allow
Allow from all
</Proxy>
ErrorLog logs/mywebapp.example.com-error_log
CustomLog logs/mywebapp.example.com-access_log common
</VirtualHost>
Eu modifiquei meu arquivo tomcat6 server.xml
e alterei o primeiro conector para incluir o proxyName
e proxyPort
.
<!-- 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.example.com"
proxyPort="8080"
redirectPort="8443" URIEncoding="UTF-8"/>
Não importa o que eu tente, quando coloco mywebapp.example.com
no meu navegador, ele redireciona para mywebapp.example.com:8080/mywebapp
.
quando eu quiser acessá-lo como mywebapp.example.com
e ficar na barra de endereço do navegador. Isso tornaria o url muito mais amigável, etc.
Eu já configurei o CNAME
em DNS
para mywebapp
.
www.example.com
não é afetado por isso.
logs para httpd
são normais ... logs para tomcat6 não mostram nada. Eu sei que o pedido atinge a caixa da direita porque www.example.com:8080/mywebapp
funciona (juntamente com os outros sites).
iptables
está desativado e, portanto, se SELinux
.
O que estou fazendo de errado? Por favor, informe.
UPDATE:
Eu tentei adicionar ProxyPreserveHost On
na configuração do vhost por um dos comentários, mas sem dados. Quando essa linha é adicionada e o apache e o tomcat são reiniciados, não consigo acessar mywebapp.example.com
nem www.example.com:8080/mywebapp
. Basicamente, adicionar essa configuração torna o mywebapp inacessível, mas sei que ainda está em execução.
UPDATE 2:
Adicionando o tcpdump obtido do servidor. Eu estou mostrando a primeira conexão como está sendo passado de pfsense
(proxy) para o 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.example.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.example.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.example.com
X-Forwarded-Server: mywebapp.example.com
Connection: Keep-Alive
192.168.2.1 > 192.168.1.1
GET /mywebapp HTTP/1.1
Host: www.example.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.example.com
X-Forwarded-Server: mywebapp.example.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.example.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.example.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.example.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.example.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.example.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.example.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.example.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.example.com:8080
DNT: 1
Connection: Keep-Alive
Cookie: JSESSIONID=81CE83D61454A8E75C222759FA118338
Update 3:
Adicionando meu arquivo /etc/httpd/conf/httpd.conf
atual para mostrar atualizações / alterações até o momento.
<VirtualHost *:80>
ServerName mywebapp.example.com
ProxyPass / http://www.example.com:8080/mywebapp/
ProxyPassReverse / http://www.example.com:8080/mywebapp/
ProxyRequests off
RewriteEngine on
RewriteRule ^(/.*) http://www.example.com:8080/mywebapp/$1 [P]
# ProxyPreserveHost On
<Proxy http://www.example.com:8080/mywebapp*>
Order deny,allow
Allow from all
</Proxy>
ErrorLog logs/mywebapp.example.com-error_log
CustomLog logs/mywebapp.example.com-access_log common
</VirtualHost>