System: centos 5.9
Environment: apache 2.2.25
Tomcat 7.0.42
Jdk 1.7.0
1. Install apache
I am directly installing yum here. If you want to compile and install it, it will not work.
The code is as follows: |
Copy code |
Yum-y install httpd-devel |
2. Install tomcat and jdk
I will not talk about it here. You can refer to my article centos installation and configuration of JDK1.7 and Tomcat7.
3. Configure httpd proxy anti-proxy tomcat
Vi/etc/httpd/conf/httpd. conf
Add at the bottom
The code is as follows: |
Copy code |
<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. Verify |
Enter http: // ip in the browser to access the tomcat homepage. You no longer need to enter http: // ip: 8080.
Tomcat-security settings
Now let's make security settings for apache and tomcat to prevent servers from being controlled by others due to tomcat vulnerabilities.
The integrated configuration of apache and tomcat is:
Vi/etc/httpd/conf/httpd. conf
Add at the bottom
The code is as follows: |
Copy code |
<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> |
Then, we add authentication between <Proxy> and </Proxy>, as shown below:
The code is as follows: |
Copy code |
<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> |
Or allow only ip addresses to access:
The code is as follows: |
Copy code |
<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> |
After saving it, restart apache to make it take effect.