1024programmer Nginx Linux system integrates Nginx+Tomcat server environment configuration

Linux system integrates Nginx+Tomcat server environment configuration

With the continuous development of the IT industry, the performance of personal and enterprise applications on the website is also constantly improving. From the previous apache+tomcat integration, weblogic and other common web applications, lighttpd, nginx
Constantly being used by enterprises, the combination of nginx+tomcat is becoming more and more widely used. The following is my nginx+Tomcat integration method. I also refer to many articles on the Internet. Thank you! Although there are many nginx+tomcat integration solutions on the Internet, there are good and bad, here is the configuration document that I personally practiced, for everyone to learn and reference! Improve each other!

1. First, we download the source package we need:
Tomcat version download, this website integrates download: jdk, please go to the following website to download:

https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=jdk-6u18-oth-JPR@CDS-CDS_Developer

Tomcat download address: http://blog.mgcrazy.com/download/apache-tomcat-6.0.30.tar.gz
[Nginx-0.8.54 download, nginx download, nginx stable version download]
http://blog.mgcrazy.com/download/nginx-0.8.54.tar.gz
http://blog.mgcrazy.com/download/pcre-8.01.tar.gz
Download to the /usr/src directory. Next we start the installation!
First install jdk:
chmod o+x jdk* && ./jdk*
;The program package will prompt you to press the Enter key. We can install it according to the prompt. After decompression, the jdk1.6.0_18 folder will be generated in the current directory, mkdir -p
/usr/java && mv jdk1.6.0_18 /usr/java/under

Add the following statement at the end of vi /etc/profile:
export JAVA_HOME=/usr/java/jdk1.6.0_18
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin
source /etc/profile //Make the environment variable take effect immediately
java ?version //Check the java version, the displayed version is 1.6.0_18, which proves that the installation is successful!

cd /usr/src && tar xzf apache-tomcat-6.0.30.tar.gz
Decompression is complete and execute mv apache-tomcat-6.0.30 /usr/local/tomcat
[Move to /usr/local and rename to tomcat folder]

cd /usr/local/tomcat/bin/ && vi setenv.sh
Create a setenv.sh script file and add the following statement
JAVA_HOME=/usr/java/jdk1.6.0_18
JAVA_JRE=/usr/java/jdk1.6.0_18/jre
Save and exit.
And set executable permissions chmod o+x setenv.sh
Start tomcat service; current directory ./startup.sh
netstat -tnl |grep 8080
Check whether port 8080 is enabled. If it is enabled, you can directly access it. If it is not enabled, please check the tomcat log for an error.

Access address: http://ip:8080
[If you see the cat page, congratulations on the successful installation of tomcat and jdk! 】

Here I point the directory of tomcat to /usr/webapps/www, without the default project of tomcat

If you want to know more tomcat server.xml more configuration will be given later. . . . . . . . .

2. [Before installing nginx, you need to install the pcre package and zlib to support rewriting, regularization and web page compression, etc.]

(1) First install pcre:

cd /usr/src &&tar xzf pcre-8.01.tar.gz &&cd
pcre-8.01 && ./configure ?prefix=/usr/local/pcre
&&make &&make install

(2), and then install nginx:

useradd www && cd /usr/src && tar xzf
nginx-0.8.54.tar.gz && cd nginx-0.8.54 &&
./configure ?prefix=/usr/local/nginx-0.8
?with-http_stub_status_module ?with-openssl=/usr/
?with-pcre=/usr/src/pcre-8.01 ?user=www ?group=www &&make
&&make install
[nginx Note*
?with-pcre=/usr/src/pcre-8.01 points to the source package decompression path, not the installation path, otherwise it will report

make[1]: *** [/usr/local/pcre/Makefile] Error 127 Error]

After nginx is installed, we configure the nginx.conf file in /usr/locla/nginx-0.8/conf
Create two new files below: nginx.conf, proxy.conf
[The two configuration files refer to Zhang Yan’s blog and other netizens’ blogs], thank them very much!

user www www;

worker_processes 8;

error_log /usr/local/nginx-0.8/logs/nginx_error.log crit;

pid /usr/local/nginx-0.8/nginx.pid;

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

worker_rlimit_nofile 65535;

events
{
use epoll;
worker_connections 65535;
}

http
{
include mime.types;
default_type application/octet-stream;

#charset gb2312;
###########404502500###############
error_page 400 404 403 500 502 503 http://blog.mgcrazy.com;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;

tcp_nodelay on;

gzip on;
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;

server
{
listen 82;
server_name 192.168.0.88;
index index.jsp index.htm index.htm;
root /usr/webapps/www;

#limit_conn crawler 20;

location ~ .*.jsp$
{

proxy_pass http://192.168.0.88:8080;

}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*.(js|css)?$
{
expires 1h;
}

log_format access ‘$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-0.8/logs/access.log access;

}
}

The above is the configuration file of nginx.conf, we create a new proxy.conf file: the following content:

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 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

The above configuration files can be modified according to the actual situation. For example, the port I listen to is 82 instead of 80, so port 82 must be added when accessing.
We use /usr/local/nginx-0.8/sbin/nginx -t to check whether the configuration file is correct and the following prompts are normal:

the configuration file /usr/local/nginx-0.8/conf/nginx.conf
syntax is ok
configuration file /usr/local/nginx-0.8/conf/nginx.conf test is
successful

After the test is ok! Let’s restart tomcat, and then start nginx: /usr/local/nginx-0.8/sbin/nginx
to start.

Enter http://192.168.0.88:82 port in the xp browser to access the jsp page under your project by default!
My test page looks like this:

JSP Test Page
Fri Mar 18 17:32:45 CST 2011

It means that the integration of Nginx+Tomcat is successful!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/linux-system-integrates-nginxtomcat-server-environment-configuration/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索