1. install Tomcat and JDK
1. Upload apache-tomcat-6.0.18.tar.gz and jdk-6u12-linux-i586.bin to/usr/local
2. Run 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. Run the following command to install JDK:
#./Jdk-6u12-linux-i586.bin
4. Configure environment variables:
Edit the profile file in/etc with the following content:
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. start Tomcat and enter http: // localhost: 8080. If the installation of Tomcat and JDK is successful
6. Create a new file directory/home/WWW as the website storage directory and set the server. in the XML file, change the pointing path of appbase = to/home/www/web in host name = "localhost ".
7. Create index. jsp to/home/www/web/root. The content is "My Web !"
Ii. Install nginx
1. Upload nginx-0.7.63.tar.gz to/usr/local
2. Run the following command to decompress nginx:
# 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 server status page and HTTPS Module
After execution, an error will be prompted, indicating that the PCRE Library is missing. This is the HTTP rewrite module, that is, the URL static package.
You can upload pcre-7.9.tar.gz and run the following command to install it:
# Tar zxvf PCRE-
7.9
.Tar.gz
# Cd PCRE-
7.9
#./Configure
# Make
# Make install
After PCRE is successfully installed, continue to install nginx
# Cd nginx-
0.7
.
63
#./Configure
# Make
# Make install
4. After nginx is installed successfully, the installation directory is/usr/local/nginx.
Create proxy. conf In the conf folder to configure some proxy parameters. The content is as follows:
#! Nginx (-)
# Proxy. conf
Proxy_redirect off;
Proxy_set_header host $ host;
Proxy_set_header X-real-IP $ remote_addr; # obtain the real IP Address
# Proxy_set_header X-forwarded-for $ proxy_add_x_forwarded_for; # obtain the real IP address of the proxy
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_buffer_size 4 K;
Proxy_buffers
4
32 K;
Proxy_busy_buffers_size 64 K;
Proxy_temp_file_write_size 64 K;
Edit nginx. conf In the conf folder under the installation directory and enter the following content:
# Username and user group for running nginx
# User WWW;
# Number of processes started
Worker_processes
8
;
# Global error logs and PID files
Error_log/usr/local/nginx/logs/nginx_error.log crit;
Pid/usr/local/nginx. PID;
# Specifies the value
For
Maximum file descriptors that can be opened
This
Process.
Worker_rlimit_nofile
65535
;
# Working mode and maximum number of connections
Events
{
Use epoll;
Worker_connections
65535
;
}
# Set the HTTP server and use its reverse proxy function to provide Load Balancing support
HTTP
{
# Set the 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 32 K;
Large_client_header_buffers
4
32 K;
Client_max_body_size 8 m;
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 64 K;
# Fastcgi_buffers
4
64 K;
# Fastcgi_busy_buffers_size 128 K;
# Fastcgi_temp_file_write_size 128 K;
# Gzip on;
# Gzip_min_length 1 K;
# Gzip_buffers
4
16 K;
# 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 10 m;
### Prohibit Website access through IP addresses
Server {
SERVER_NAME _;
Return
404
;
}
Server
{
Listen
80
;
SERVER_NAME localhost;
Index index.html index.htm index. jsp; # Set the default homepage address for access
Root/home/www/web/root; # set the path for storing website resources
# Limit_conn Crawler
20
;
Location ~ . *. Jsp $ # All JSP pages are handled by Tomcat
{
Index index. jsp;
Proxy_pass http:
// Localhost: 8080; # Switch to Tomcat for processing
}
Location ~ . * \. (GIF | JPG | JPEG | PNG | BMP | SWF) $ # Set to directly read static files without passing through Tomcat
{
Expires 30d;
}
Location ~ . * \. (JS | CSS )? $
{
Expires 1 h;
}
# Define the write format of access logs
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 path for storing access logs
}
}
5. 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
If the message "unknown host" is displayed, run the following command on the server: Ping www.baidu.com. If the message "unknown host" is also displayed, there are two possibilities:
A. Check whether the DNS server address is set in/etc/resolv. conf. If no DNS server address is set, add
B. Firewall Interception
6. Start nginx commands
#/Usr/local/nginx/sbin/nginx
Enter the following command to view the nginx master process number:
PS-Ef | grep
"Nginx: Master process"
| Grep-V
"Grep"
| Awk-F
''
'{Print $2 }'
7. Stop nginx commands
#/Usr/local/nginx/sbin/nginx-s stop
8. smoothly change the nginx configuration without stopping the nginx Service
A. 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
B. Enter the following command to view the nginx master process number:
PS-Ef | grep
"Nginx: Master process"
| Grep-V
"Grep"
| Awk-F
''
'{Print $2 }'
The screen displays the nginx main process number, for example:
6302
Then, run the following command to make the modified nginx configuration file take effect:
Kill-HUP
6302
Alternatively, you can find the nginx PID file:
Kill-HUP 'cat/usr/local/nginx. Pi'
9. Start tomcat after nginx is started. Enter http: // host IP address to view "My Web !"
Iii. Others
Stub_status
Syntax: stub_status on
Default Value: None
Scope: Location
Create a location region to enable stub_status
The status information returned by the stub Status Module is similar to that returned by mathopd's. The returned status information is as follows:
Active connections:
291
Server accepts handled requests
16630948
16630948
31070465
Reading:
6
Writing:
179
Waiting:
106
Active connections-number of active connections initiated to the backend
Server accepts handled requests-nginx processes a total of 16630948 connections and successfully creates 16630948 handshakes (proving that there is no failure in the middle ), A total of 31070465 requests are processed (an average of 1.8 data requests are processed in each handshake)
Reading-Number of headers that nginx reads to the client
Number of headers that writing-nginx returns to the client
When waiting-enables keep-alive, this value is equal to active-(Reading + writing), which means nginx says it has processed the resident connection waiting for the next request command.