CentOS under Nginx+tomcat installation configuration Nginx combined with Tomcat

Source: Internet
Author: User

First, install tomcat:

(1), install the JDK:

http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u3-download-1501626.html

[Root@localhost java]# mkdir-p/usr/java

[Root@localhost java]# tar zxvf jdk-7u3-linux-x64.tar.gz-c/usr/java/

[Root@localhost java]# Vi/etc/profile


Java_home= "/usr/java/jdk1.7.0_03"

Jre_home= "/usr/java/jdk1.7.0_03/jre" #没有这个配置后面的tomcat关闭时会报错.

Classpath= $CLASSPATH: $JAVA _home/lib: $JAVA _home/jre/lib

Path= $JAVA _home/bin: $JAVA _home/jre/bin: $PATH

Export Java_home
Export Jre_home
Export CLASSPATH
Export PATH USER LOGNAME MAIL HOSTNAME histsize INPUTRC


[Root@localhost java]# Source/etc/profile

[Root@localhost java]# Java-version

Java Version "1.7.0_03"

Java (TM) SE Runtime Environment (build 1.7.0_03-b04)

Java HotSpot (TM) 64-bit Server VM (build 22.1-b02, Mixed mode)

ii. installation of Tomcat:

Tomcat Download:

http://tomcat.apache.org/

# tar zxvf apache-tomcat-7.0.26.tar.gz-c/usr/src/

# cd/usr/src/

# CP-RF Apache-tomcat-7.0.26/usr/local/tomcat

# CP-RF APACHE-TOMCAT-7.0.26/USR/LOCAL/TOMCAT1


The first Tomcat installed in/usr/local/tomcat

# Cd/usr/local/tomcat

# Vi/etc/profile

In add $tomcat_home/common/lib/servlet.jar after Classpath

In Add after path: $CATALINA _home/lib

Export Tomcat_home=/usr/local/tomcat
Export Catalina_home=/usr/local/tomcat
Export Catalina_base=/usr/local/tomcat
Export path= $PATH: $CATALINA _home/lib
Export classpath= $CLASSPATH: $CATALINA _home/common/lib/servlet.jar

Will be a second Tomcat installed in/USR/LOCAL/TOMCAT1

Setting environment variables

#vi/etc/profile

In add $tomcat_2_home/common/lib/servlet.jar after Classpath

In Add after path: $CATALINA _2_home/lib

Export TOMCAT_1_HOME=/USR/LOCAL/TOMCAT1
Export CATALINA_1_HOME=/USR/LOCAL/TOMCAT1
Export CATALINA_1_BASE=/USR/LOCAL/TOMCAT1
Export path= $PATH: $CATALINA _1_home/lib
Export classpath= $CLASSPATH: $CATALINA _1_home/common/lib/servlet.jar

Save exit

: Wq

Make environment variables effective

#source/etc/profile

Modify Tomcat configuration file Vi/usr/local/tomcat1/conf/server.xml (if two Tomcat is not on the same machine can not modify the port)

The following content

...

.../>

Revision changed to

...

.../>

Modify Tomcat configuration boot file/usr/local/tomcat1/bin/startup.sh

In Add the following on the exec

Export java_home=/usr/java/jdk1.7.0_03

Export JRE_HOME=/USR/JAVA/JDK1.7.0_03/JRE

Export Classpath= $JAVA _home/lib

Export path= $JAVA _home/bin: $PATH

% Note that many online written export path= $JAVA _home/bin, will report error at startup

Export Catalina_home= $CATALINA _2_home

Export catalina_base= $CATALINA _2_base

Modify Tomcat configuration boot file/usr/local/tomcat2/bin/shutdown.sh

In Add the following on the exec

Export java_home=/usr/local/java/jdk1.7.0_03

Export JRE_HOME=/USR/JAVA/JDK1.7.0_03/JRE

Export Classpath= $JAVA _home/lib

Export path= $JAVA _home/bin: $PATH

Export Catalina_home= $CATALINA _2_home

Export catalina_base= $CATALINA _2_base

Start TOMCAT

/usr/local/tomcat1/bin/startup.sh

Browser input: http://127.0.0.1:9080/

Shut down TOMCAT

/usr/local/tomcat1/bin/shutdown.sh


Third, install nginx:

Nginx Download: HTTP://WIKI.CODEMONGERS.COM/NGINXCHS

Pcre: http://sourceforge.net/projects/pcre/files/pcre/8.30/

Upstream: http://code.google.com/p/nginx-upstream-jvm-route/downloads/detail?name= nginx-upstream-jvm-route-0.1.tar.gz&can=2&q=

(1), installation pcre:

# tar zxvf pcre-8.30.tar.gz-c/usr/src/

# cd/usr/src/pcre-8.30/

# ./ Configure

# Make && make install

(2), install plug-in upstream,

# tar zxvf nginx-1.0.13.tar.gz-c/usr/src/

# tar zxvf nginx-upstream-jvm-route-0.1.tar.gz-c/usr/src/

Note Here is the decompression to the same folder, where the default name is nginx-1.0.13

# cd/usr/nginx-1.0.13/

# Patch-p0 </usr/nginx-1.0.13/nginx_upstream_jvm_route/jvm_route.patch

(3), installation Nginx:

#./configure--prefix=/usr/local/nginx--with-http_stub_status_module--with-pcre=/usr/src/pcre-8.30--add-module= /usr/src/nginx_upstream_jvm_route--with-openssl=/usr/( --user=--group=)

# Make && make install

(4), editor nginx.conf:

# vi/usr/local/nginx/conf/nginx.conf

User nobody;

Worker_processes 8;

Error_log Logs/nginx_error.log Crit;

Pid /usr/local/nginx/nginx.pid;

#Specifies the value for maximum file descriptors the can is opened by this process.

Worker_rlimit_nofile 20480;

Events

{

Use Epoll;

Worker_connections 20480;

}

HTTP {

Upstream AA {

server 127.0.0.1:8080 max_fails=3 fail_timeout=50s;

}

Upstream BB {

server 127.0.0.1:8081 max_fails=3 fail_timeout=50s;

}

Include mime.types;

Default_type Application/octet-stream;

#charset gb2312;

CharSet UTF-8;

Server_names_hash_bucket_size 128;

Client_header_buffer_size 32k;

Large_client_header_buffers 4 32k;

Client_header_timeout 20;

Client_max_body_size 20m;

Sendfile on;

Tcp_nopush on ;

Keepalive_timeout 60;

Tcp_nodelay on;

Proxy_connect_timeout 30;

Proxy_read_timeout 60;

Proxy_send_timeout 20;

Proxy_buffer_size 96k;

Proxy_buffers 8 256k;

Proxy_busy_buffers_size 512k;

Proxy_temp_file_write_size 512k;

# Proxy_store on;

# proxy_store_access USER:RW GROUP:RW all:rw;

Proxy_temp_path/usr/local/nginx/proxy_temp;

Proxy_cache_path/usr/local/nginx/www levels=1:2 keys_z inactive=1d max_size=2g;

gzip on;

Gzip_proxied any;

Gzip_min_length 1k;

Gzip_buffers 4 16k;

Gzip_http_version 1.0;

Gzip_comp_level 2;

Gzip_types text/plain application/x-javascript text/css application/xml;

Gzip_vary on;

# Limit_zone one $binary _remote_addr 10m;

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for $remote _addr;

server {

Listen;

server_name 192.168.3.30;

index index.html;

# rewrite ^/index.html/last;

#rewrite ^/(. *) _p ([0-9]*) _ (. *) _e (. *)/(. *) _ (. *) _t (. *) _o (. *) _ (l|s|k|[ 0-9]*) $ /searchclassbigkey?skey=$1&pno=$2&sw=$3&pe=$4&rk=$5&dekey=$6&tid=$7&ocs=$8 &ocid=$9 last;

#rewrite ^/(. *) _p ([0-9]*) _s (. *)/(. *) _ (. *) _ (. *) $/searchkey?skey=$1&pno=$2&sw=$3&pe=$4&rk=$5& Dekey=$6 last;

# rewrite ^/d-(. *) $ /detaillist?id=$1 last;

Location/

{

# proxy_next_upstream http_502 http_504 error timeout invalid_header;

# proxy_headers_hash_max_size 1024x768;

# proxy_headers_hash_bucket_size;

# Proxy_cache Cache_one;

proxy_cache_valid 304 2h;

proxy_cache_valid any 30m;

proxy_cache_key $host $uri$is_args$args;

# proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

Proxy_pass Http://aa;

}

Location ~. *\. (gif|jpg|jpeg|png|bmp|swf) $

{

# Proxy_cache Cache_one;

proxy_cache_valid 304 5h;

proxy_cache_valid any 3m;

proxy_cache_key $host $uri$is_args$args;

expires 8h;

Proxy_pass Http://aa;

}

Location ~. *\. (js|css|html) $

{

# Proxy_cache Cache_one;

proxy_cache_valid 304 3h;

proxy_cache_valid any 3m;

proxy_cache_key $host $uri$is_args$args;

expires 5h;

Proxy_pass Http://aa;

}

Log_format AA ' $remote _addr-$remote _user [$time _local] "$request" '

' $status $body _bytes_sent ' $http _referer '

' "$http _user_agent" $http _x_forwarded_for ';

Access_log/usr/local/nginx/logs/aa.log AA;

}

server {

Listen;

server_name 192.168.3.31;

index index.html;

Location/

{

Proxy_cache Cache_one;

proxy_cache_valid 304 2h;

proxy_cache_valid any 3m;

proxy_cache_key $host $uri$is_args$args;

Proxy_pass http://bb;

}

Location ~. *\. (gif|jpg|jpeg|png|bmp|swf|js|css|html) $

{

Proxy_cache Cache_one;

proxy_cache_valid 304 5h;

proxy_cache_valid any 3m;

expires 8h;

proxy_cache_key $host $uri$is_args$args;

Proxy_pass http://bb;

}

Log_format BB ' $remote _addr-$remote _user [$time _local] "$request" '

' $status $body _bytes_sent ' $http _referer '

' "$http _user_agent" $http _x_forwarded_for ';

Access_log/usr/local/nginx/logs/bb.log BB;

}

}

#/usr/local/nginx/sbin/nginx-t

Nginx:the configuration file/usr/local/nginx/conf/nginx.conf syntax is OK

Nginx:configuration file/usr/local/nginx/conf/nginx.conf Test is successful

#/usr/local/nginx/sbin/nginx

# NETSTAT-ANPT | grep 80

Tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 30169/nginx

#/usr/local/nginx/sbin/nginx–s Reload

The above describes the CentOS under the Nginx+tomcat installation configuration Nginx combined with Tomcat, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.