我有一个“简单”的问题,可能会在几秒钟内回答;)我设置了一个Apache Web服务器(V2.2),这个Apache服务器作为平衡与“mod_jk”启用。 该服务器上托pipe了2个不同的应用程序,称为“低”和“高”。 我正在使用的Tomcat服务器是V6.0x服务器。
这里来的Apache httpd.conf(摘要):
# Load mod_jk module LoadModule jk_module modules/mod_jk-1.2.30-httpd-2.2.3.so # Where to find workers.properties JkWorkersFile conf/workers.properties # loadbalancer contains the first application that may be clustered (runs on more tomcat instances/servers) JkMount /high/* loadbalancer # webworker contains the second application that runs in a single tomcat instance JkMount /low/* webworker
你可以看到有两个定义的映射。 第一个“高”去负载均衡器(2个应用程序服务器“worker1”和“worker2”,见下面的worker.properties)。 第二个parsing为“低”,并转到webworker(这个服务器上的另一个tomcat实例)。
这里是worker.properties:
# Define worker list worker.list=worker1,worker2,loadbalancer,webworker # Set properties for worker1 (ajp13, http=8080, https=8443) # Note: worker1 runs on the same machine as the serving apache webserver worker.worker1.type=ajp13 worker.worker1.host=appserver1.example.com worker.worker1.port=8009 worker.worker1.lbfactor=1 # Set properties for worker2 (ajp13, http=8080, https=8443) # Note: worker2 runs on a different machine worker.worker2.type=ajp13 worker.worker2.host=appserver2.example.com worker.worker2.port=8010 worker.worker2.lbfactor=2 # Set properties for webworker (ajp13, http=9090, https=9443) # Note: webworker runs on the same machine as the serving apache webserver worker.webworker.type=ajp13 worker.webworker.host=appserver1.example.com worker.webworker.port=8010 # Set properties for load balancer worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=worker1, worker2
所以,这是我的问题:
我如何设置映射“低”的所有请求应该被重写为“https”? 第二个应用程序“低”应该是完全安全的。
即调用“ http://www.myapplication.com/low ”导致Apache服务器将其重写为“ https://www.myapplication.com/low ”。
这可能与“mod_rewrite”? 我在哪里必须放置证书文件? 是否在tomcat-config(server.xml)或apache-config(或者在两个configuration文件)中configuration证书?
Thx为你的帮助:)
find了解决办法:
布鲁诺帮了我,所以这是我的工作configuration(将configuration放在另外一个名为httpd-vhosts.conf的文件中):
<IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin [email protected] ServerName appserver1.example.com:443 SSLEngine on SSLCertificateFile "conf/ssl.crt/server.crt" SSLCertificateKeyFile "conf/ssl.key/server.key" JkMount /low/* webworker </VirtualHost> </IfModule> <VirtualHost *:80> ServerAdmin [email protected] ServerName appserver1.example.com JkMount /high/* loadbalancer <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/low(.*) https://appserver1.example.com/low$1 [R,L] </IfModule> </VirtualHost>
你有没有尝试过这样的事情(假设你已经加载了mod_rewrite)?
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/low(.*) https://%{SERVER_NAME}/low$1 [R,L]
如果您使用Apache Httpd作为前端,则需要configurationSSL(请参阅mod_ssl模块的文档 )。
通常,这看起来像这样:
<IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin [email protected] ServerName host.name.example SSLEngine on SSLCertificateFile /etc/ssl/certs/host.pem SSLCertificateKeyFile /etc/ssl/private/host.key # ... # (the config file with your distribution will probably have # a sensible set of options for SSL as well.) JkMount /high/* loadbalancer JkMount /low/* webworker </VirtualHost> </IfModule> <VirtualHost *:80> ServerAdmin [email protected] ServerName host.name.example # You can put the rewrite rules here for example. JkMount /high/* loadbalancer # Don't put this one if you don't want it over plain HTTP # JkMount /low/* webworker </VirtualHost>