Details of Linux Nginx+Tomcat integration installation and configuration
- 2020-05-17 07:28:09
- OfStack
1. Install Tomcat and JDK
1. Upload apache-tomcat-6.0.18.tar.gz and jdk-6u12-linux-i586.bin to /usr/local
2. Execute the following command to install tomcat:
#cd /usr/local
#tar zxvf apache-tomcat-6.0.18.tar.gz
After decompression, rename apache-tomcat-6.0.18 to tomcat
3. Install JDK by following commands:
#./jdk-6u12-linux-i586.bin
4. Configure environment variables:
Edit the profile file under /etc and add the following:
JAVA_HOME="/usr/local/jdk1.6.0_12"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:$JAVA_HOME/bin "
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME
5. Launch tomcat and enter http://localhost:8080. If you see the cat page, tomcat and jdk have been installed successfully
6. Create a new file directory /home/www for the website directory, set server.xml file, and change the pointing path of appBase= to /home/www/web at Host name= "localhost"
7, create index. jsp to/home/www/web/ROOT, content is: "My web!"
2. Install Nginx
1. Upload nginx-0.7.63.tar.gz to /usr/local
2. Unzip nginx by following command:
#cd /usr/local
#tar zxvf nginx-0.7.63.tar.gz
3. Compile and install nginx
#cd nginx-0.7.63
#./configure --with-http_stub_status_module --with-http_ssl_module # Start the server Status page and https The module
At the end of the execution, there will be an error saying PCRE library is missing. This is the HTTP Rewrite module, which is the static package of url
You can upload pcre-7.9.tar.gz and enter the following command to install:
#tar zxvf pcre-7.9.tar.gz
#cd pcre-7.9
#./configure
#make
#make install
After successfully installing pcre, continue installing nginx
#cd nginx-0.7.63
#./configure
#make
#make install
4. After the successful installation of nginx, the installation directory is /usr/local/nginx
Create a new proxy.conf in the conf folder to configure some proxy parameters, as follows:
#!nginx (-)
# proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; # Get real ip
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # Get the truth of the agent ip
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;
Edit nginx.conf in the conf folder under the installation directory and enter the following
# run nginx The user name and user group you are in
#user www www;
# Number of startup processes
worker_processes 8;
# Global error logging and PID file
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
# Working mode and maximum number of connections
events
{
use epoll;
worker_connections 65535;
}
# set http The server, with its reverse proxy function to provide load balancing support
http
{
# set mime type
include mime.types;
default_type application/octet-stream;
include /usr/local/nginx/conf/proxy.conf;
#charset gb2312;
# Set request buffer
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;
# fastcgi_connect_timeout 300;
# fastcgi_send_timeout 300;
# fastcgi_read_timeout 300;
# fastcgi_buffer_size 64k;
# fastcgi_buffers 4 64k;
# fastcgi_busy_buffers_size 128k;
# fastcgi_temp_file_write_size 128k;
# 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;
#limit_zone crawler $binary_remote_addr 10m;
### Prohibited by ip Access to the site
server{
server_name _;
return 404;
}
server
{
listen 80;
server_name localhost;
index index.html index.htm index.jsp;# Set the default home address for access
root /home/www/web/ROOT;# Set the location of the site's resources
#limit_conn crawler 20;
location ~ .*.jsp$ # all jsp All pages are submitted tomcat To deal with
{
index index.jsp;
proxy_pass http://localhost:8080;# Turn to tomcat To deal with
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ # Set access to static files to read directly without passing through tomcat
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
# Define the write format for the access log
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/logs/localhost.log access;# Set the access log storage path
}
}
5, modify/usr/local/nginx/conf/nginx conf configuration file, please perform the following command to check the configuration file is correct:
#/usr/local/nginx/sbin/nginx -t
If the screen displays the following two lines of information, 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
If unknown host is prompted, ping www. baidu. com unknown host can be executed on the server: ping www. baidu. com
a, the server has not set the DNS server address, check whether it is set under /etc/ resolv. conf, if not, add it
b, firewall interception
6. Start the command nginx
#./jdk-6u12-linux-i586.bin
0
At this point, enter the following command to view the Nginx main process number:
#./jdk-6u12-linux-i586.bin
1
7. Stop nginx
#./jdk-6u12-linux-i586.bin
2
8. Smooth changes to the Nginx configuration without stopping the Nginx service
a, modify/usr local nginx/conf/nginx conf configuration file, please perform the following command to check the configuration file is correct:
/usr/local/nginx/sbin/nginx -t
If the screen displays the following two lines of information, 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
At this point, enter the following command to view the Nginx main process number:
#./jdk-6u12-linux-i586.bin
4
The screen displays the Nginx main process number, for example:
6302
At this point, execute the following command to effect the modified Nginx configuration file:
#./jdk-6u12-linux-i586.bin
5
Or find the Pid file for Nginx without the hassle:
#./jdk-6u12-linux-i586.bin
6
9. After starting nginx, start tomcat. Enter http:// host ip address to see "My web!"
3. The other
stub_status
Syntax: stub_status on
Default: None
Scope: location
Create an location zone to enable stub_status
The status information returned by the "stub status" module is very similar to that of mathopd's. The status information returned is as follows:
#./jdk-6u12-linux-i586.bin
7
active connections - number of active connections initiated to the back end
server accepts handled requests -- nginx processed a total of 16630948 connections, successfully created 16630948 handshakes (proving that there were no failures in the middle), and processed a total of 31070465 requests (1.8 data requests per handshake on average).
reading -- nginx reads the number of Header messages to the client
writing - the number of Header messages that nginx returns to the client
waiting - when keep-alive is turned on, this value is equal to active wok (reading + writing), which means that Nginx says it has finished processing the resident connection waiting for the next request