Configure the nginx + tomcat + jdk java environment in Centos/redhat

Source: Internet
Author: User

 

Nginx installation is not mentioned in this article.

I. jdk installation

Jdk download address: http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html

Select the appropriate jdk from the above page and download it to the/root/directory. I chose jdk-6u20-linux-i586.bin.

After the download, modify the file properties of the jdk-6u23-linux-i586.bin to be executable and then execute the program to install JDK:

Chmod + x jdk-6u20-linux-i586.bin
/Jdk-6u20-linux-i586.bin

Press the space key to view the protocol. When the prompt "Do you agree to the above license terms?" appears? [Yes or no] ", enter" yes ". After the installation is complete, run the following statement:

Mv jdk1.6.0 _ 23/usr/local/jdk

Edit the profile File settings boot file java boot execution environment file:

Vi/etc/profile

Add the following content at the end of the file:

JAVA_HOME = "/usr/local/jdk"
CLASS_PATH = "$ JAVA_HOME/lib: $ JAVA_HOME/jre/lib"
PATH = "$ JAVA_HOME/bin:.: $ PATH"
CATALINA_HOME = "/usr/local/tomcat"
Export JAVA_HOME CATALINA_HOME

Save and exit vi. Run the following command to make the configuration take effect:

Source/etc/profile

II. tomcat installation

Put apache-tomcat-6.0.35 in the/root/directory, copy it to the/user/local/directory, and rename it tomcat:

Mv apache-tomcat-6.0.23/usr/local/tomcat

Create the webpage root directory:

Mkdir/www
Cp-rf/usr/local/tomcat/webapps/*/www/

Configure the tomcat server. xml file:

Vim/usr/local/tomcat/conf/server. xml
Search for appBase = "webapps" and change it to appBase = "/www"./www is the root directory of the webpage.

After modification, start tomcat. The default listening port is 8080:

/Usr/local/tomcat/bin/startup. sh

To stop tomcat, run the following command:

/Usr/local/tomcat/bin/shutdown. sh

Note: Permission denied occurs when you execute./startup. sh or./shutdown. sh,

In fact, it is very simple, that is, when executing tomcat, the user does not have the permission, and thus cannot execute,

Run the command chmod to modify the. sh permission in the bin directory:

Chmod u + x *. sh

Run/usr/local/tomcat/bin/startup. sh (or/usr/local/tomcat/bin/shutdown. sh) again.

III. Integration of nginx and tomcat

To integrate Nginx with tomcat, you only need to configure the nginx. conf file.

View and modify the nginx. conf file:

Vim/usr/local/nginx/conf/nginx. conf
Http
    {
..........
       
Client_body_buffer_size 512 k;
Proxy_connect_timeout 5;
Proxy_read_timeout 60;
Proxy_send_timeout 5;
Proxy_buffer_size 16 k;
Proxy_buffers 4 64 k;
Proxy_busy_buffers_size 128 k;
Proxy_temp_file_write_size 128 k;
       
Upstream tomcat_server {
Server 127.0.0.1: 8080;
        }
...........
Server
    {
...........
If (-d $ request_filename)
        {
Rewrite ^/(. *) ([^/]) $ http: // $ host/$1 $2/permanent;
        }
Location ~ \. (Jsp | jspx | do | wsdl )? $ {
Proxy_set_header Host $ host;
Proxy_set_header X-Forwarded-For $ remote_addr;
Proxy_pass http: // tomcat_server;
        }
...............
     }

In the configuration file, static HTML web pages, images, js, css, Flash, and so on are processed using Nginx for faster speed. The file extension is. JSP ,. do and wsdl requests are processed by Nginx Reverse proxy Tomcat HTTP server.

After modifying the/usr/local/nginx/conf/nginx. conf configuration file, run the following command to check whether the configuration file is correct:

/Usr/local/nginx/sbin/nginx-t

If the following two lines of information are displayed, the configuration file is correct:

The configuration file/usr/local/nginx/conf/nginx. conf syntax is OK
The configuration file/usr/local/nginx/conf/nginx. conf was tested successfully

Restart nginx:

/Usr/local/nginx/sbin/nginx-s reload

After nginx is started, you can access the jsp instance program in the following URL to check whether the jsp program can run.
Http: // localhost/examples/jsp/
Note: The working principle of nginx and tomcat is that the nginx proxy tomcat outputs the webpage. Therefore, if the firewall is enabled, the firewall can access the jsp page without opening port 8080.

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.