一个典型的centos + apache httpd + tomcat的配置

典型的java网站: 用centos做操作系统,用tomcat提供服务,用apache httpd做反向代理

apache httpd配置

引用

#一个IP多个域名

NameVirtualHost *:80

#禁止直接使用ip访问

<VirtualHost *:80>

        ServerName 11.11.11.11

        <Location />

           Order deny,allow

            Deny from all

        </Location>

</VirtualHost>

#顶级域名跳转到www域名

<VirtualHost *:80>

    ServerName my.com

    RewriteEngine on

    RewriteCond %{http_host} ^my.com [NC]

    RewriteRule ^(.*)$ http://www.my.com/$1 [L,R=301]

</VirtualHost>

#把对apache的访问指向tomcat

<VirtualHost *:80>

    ServerName www.my.com

    ProxyPass / http://localhost:8080/

    ProxyPassReverse / http://localhost:8080/

</VirtualHost>

tomcat配置(server.xml)

引用

<!–修改proxyName和proxyPort, 使得request.getServerName()和request.getServerPort()方法拿到的是用户请求的域名和端口–>

    <Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443"

               proxyName="www.my.com"
               proxyPort="80"  
           

               />

注:这里的tomcat应用的contextPath是"/", 实际上也最好只有"/",而不是其它。否则当tomcat应用里执行  "redirect:/" 时会绕过httpd反向代理,除非你使用mod_proxy_html插件。

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.