系統:centos 5.9
環境:apache 2.2.25
tomcat 7.0.42
jdk 1.7.0
1.安裝apache
我這裡是直接yum安裝的,如果你們要編譯安裝也不是不行.
| 代碼如下 |
複製代碼 |
|
yum -y install httpd httpd-devel |
2.安裝tomcat和jdk
這裡我就不說了,大家可以去看我這篇文章centos安裝配置JDK1.7與Tomcat7.
3.配置httpd proxy反代tomcat
vi /etc/httpd/conf/httpd.conf
在最下面添加
| 代碼如下 |
複製代碼 |
|
<VirtualHost *:80>
ServerAdmin rocdk890@gmail.com
directoryIndex index.html index.php index.htm index.shtml login.php
ServerName 54.250.x.x
<IfModule proxy_module>
<IfModule proxy_http_module>
ProxyRequests Off
ProxyPass /images !
ProxyPass /css !
ProxyPass /js !
ProxyPass / balancer://example/
<Proxy balancer://example/>
BalancerMember http://54.250.x.x:8080/
</Proxy>
</IfModule>
</IfModule>
</VirtualHost>
4.驗證 |
直接在瀏覽器上輸入http://ip,就可以訪問到tomcat首頁了,再也不用去輸入http://ip:8080了,好了,就到這裡吧.
tomcat-安全設定
現在我們來做下apache和tomcat的安全設定,以避免因為tomcat的漏洞而讓伺服器被別人控制.
apache和tomcat整合的配置是:
vi /etc/httpd/conf/httpd.conf
在最下面添加
| 代碼如下 |
複製代碼 |
|
<VirtualHost *:80>
ServerAdmin rocdk890@gmail.com
directoryIndex index.html index.php index.htm index.shtml login.php
ServerName 54.250.x.x
<IfModule proxy_module>
<IfModule proxy_http_module>
ProxyRequests Off
ProxyPass /images !
ProxyPass /css !
ProxyPass /js !
ProxyPass / balancer://example/
<Proxy balancer://example/>
BalancerMember http://54.250.x.x:8080/
</Proxy>
</IfModule>
</IfModule>
</VirtualHost> |
然後我們在<Proxy>和</Proxy>中間添加身分識別驗證,如下
| 代碼如下 |
複製代碼 |
|
<VirtualHost *:80>
ServerAdmin rocdk890@gmail.com
directoryIndex index.html index.php index.htm index.shtml login.php
ServerName 54.250.x.x
<IfModule proxy_module>
<IfModule proxy_http_module>
ProxyRequests Off
ProxyPass /images !
ProxyPass /css !
ProxyPass /js !
ProxyPass / balancer://example/
<Proxy balancer://example/>
BalancerMember http://54.250.x.x:8080/
authtype basic
authname "Please enter your password:"
authuserfile /var/www/vhosts/htpasswd
require valid-user
</Proxy>
</IfModule>
</IfModule>
</VirtualHost> |
或者讓其只能ip訪問:
| 代碼如下 |
複製代碼 |
|
<VirtualHost *:80>
ServerAdmin rocdk890@gmail.com
directoryIndex index.html index.php index.htm index.shtml login.php
ServerName 54.250.x.x
<IfModule proxy_module>
<IfModule proxy_http_module>
ProxyRequests Off
ProxyPass /images !
ProxyPass /css !
ProxyPass /js !
ProxyPass / balancer://example/
<Proxy balancer://example/>
BalancerMember http://54.250.x.x:8080/
Order deny,allow
Deny from all
Allow from 192.168.10.0/24
Allow from 127.0.0.1
Allow from 54.250.x.x/28
</Proxy>
</IfModule>
</IfModule>
</VirtualHost> |
儲存之後,重啟apache使其生效就可以了.