Integrate tomcat environment and security configuration in apache

Source: Internet
Author: User
Tags centos

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.