Use nginx + Tomcat to replace Apache + jk + Tomcat

Source: Internet
Author: User

Use nginx + Tomcat to replace Apache + jk + Tomcat

# Wget http://sysoev.ru/nginx/nginx-0.6.26.tar.gz

# Tar zxvf nginx-0.6.26.tar.gz

# Cd nginx-0.6.26

# [Root @ test nginx-0.6.26] #./configure

./Configure: error: the HTTP rewrite module requires the PCRE Library.

You can either disable the module by using -- without-http_rewrite_module

Option, or install the PCRE Library into the system, or build the PCRE Library

Statically from the source with nginx by using -- With-PCRE = <path> option.

[Root @ test nginx-0.6.26] # rpm-Qa | grep PCRE

Pcre-6.6-1.1

[Root @ test suantop] # rpm-IVH pcre-devel-6.6-1.1.i386.rpm

Warning: pcre-devel-6.6-1.1.i386.rpm: Header V3 DSA Signature: nokey, key ID 37017186

Preparing... ######################################## ### [100%]

1: PCRE-devel ##################################### ###### [100%]

[Root @ test suantop] # rpm-Qa | grep PCRE

Pcre-6.6-1.1

Pcre-devel-6.6-1.1

Execute again./configure

[Root @ test nginx-0.6.26] #./configure -- with-http_stub_status_module

[Root @ test nginx-0.6.26] # Make

[Root @ test nginx-0.6.26] # make install

Modify the configuration file/usr/local/nginx/CONF/nginx. conf

Some major changes are provided.

User nobody Nobody;

Worker_processes 2;

Error_log logs/error. Log notice;

PID logs/nginx. PID;

Events {

Worker_connections 1024;

}

HTTP {

Include mime. types;

Default_type application/octet-stream;

Include/usr/local/nginx/CONF/Proxy. conf;

# The above line is added

Server {

Listen 81;

SERVER_NAME localhost;

Charset gb2312;

# Serve static files

Location ~ ^/(Images | pages | JavaScript | JS | CSS | flash | media | static )/{

Root/usr/local/WWW;

Expires 30d;

Location /{

Root/usr/local/WWW;

Index index. jsp index.htm;

Proxy_pass http: // 192.168.1.250: 8080;

}

Location/nginxstatus {

Stub_status on;

Access_log on;

Auth_basic "nginxstatus ";

}

It indicates that the file proxy. conf mentioned in the configuration file can be a VI file as follows:

[Root @ test conf] # Cat proxy. conf

#! Nginx (-)

# Proxy. conf

Proxy_redirect off;

Proxy_set_header host $ host;

Proxy_set_header X-real-IP $ remote_addr;

Proxy_set_header X-forwarded-for $ proxy_add_x_forwarded_for;

Client_max_body_size 10 m;

Client_body_buffer_size 128 K;

Proxy_connect_timeout 90;

Proxy_send_timeout 90;

Proxy_read_timeout 90;

Proxy_buffers 32 4 K;

Test Configuration File

[Root @ test conf] #/usr/local/nginx/sbin/nginx-T

15:40:02 [info] 2363 #0: the configuration file/usr/local/nginx/CONF/nginx. conf syntax is

OK

15:40:02 [info] 2363 #0: the configuration file/usr/local/nginx/CONF/nginx. conf was tested

Successfully

Start

[Root @ test conf] #/usr/local/nginx/sbin/nginx

[Root @ test conf] # ps Fax

9400? SS 0: 00 nginx: Master process/usr/local/nginx/sbin/nginx

9401? S 0: 00/_ nginx: Worker Process

9402? S 0: 00/_ nginx: Worker Process

Http: // 192.168.1.250: 81/nginxstatus

Active connections: 1

Server accepts handled requests

2 2 11

Reading: 0 writing: 1 waiting: 0

Http: // 192.168.1.250: 81.

Similarly, we can allow squid to listen to port 80 so that the proxy is transparent.

View Server Information

[Root @ test conf] # curl-I http: // localhost

HTTP/1.0 200 OK

Server: nginx/0.6.26

Date: Sun, 04 May 2008 07:18:27 GMT

Content-Type: text/html; charset = GBK

Set-COOKIE: JSESSIONID = 0ce2d90115efde9830215a55414bf11f; Path =/

X-Cache: Miss from test.suantop.com

Via: 1.0 test.abc.com (squid/3.0.stable2)

Connection: Close

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.