I. Configuration objectives
1. Install the basic environment through lnmp
After lnmp is installed, refer to the official instructions for the software. After installation, I upgraded the nginx version through official instructions.
2. Configure nginx to meet the need for reuse on a single machine in the php + java environment
II. Installation Instructions
1. Install tomcat on/usr/local/tomcat6
2. Install nginx on/usr/local/nginx
3. Install the java project under tomcat6/webapps
4. Install php-related projects directly under/usr/local/.
III. Configuration instructions
Mainly describes the situation of several main configuration files
1. nginx. conf
User www;
Worker_processes 1;
Error_log/home/wwwlogs/nginx_error.log crit;
Pid/usr/local/nginx/logs/nginx. pid;
# Specifies the value for maximum file descriptors that can be opened by this process.
Worker_rlimit_nofile 51200;
Events
{
Use epoll;
Worker_connections 51200;
}
# Fastcgi parameter configuration is very important. Great impact on performance
Http
{
Include mime. types;
Default_type application/octet-stream;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 k;
Large_client_header_buffers 4 32 k;
Client_max_body_size 50 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 256 k;
Fastcgi_buffers 8 256 k;
Fastcgi_busy_buffers_size 512 k;
Fastcgi_temp_file_write_size 512 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;
# Log format
Log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
# The core points out the configuration file location of each domain name, which is in the nginx/conf/vhost Directory
Include vhost/*. conf;
}
2. vhost (the configuration file location corresponding to the relevant domain name is specified in nginx. conf)
(1) php project configuration: file name shequ.jiuchongju.com. conf
Here I will display the configuration of a domain name here: shequ.jiuchongju.com
Server
{
Listen 80;
Server_name shequ.jiuchongju.com;
Index index.html index.htm index. php;
Root/usr/local/discuzx/upload;
Location ~ . * \. (Php | php5 )? $
{
Try_files $ uri = 404;
Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_index index. php;
Fcinclude GI. conf;
}
Location/status {
Stub_status on;
Access_log off;
}
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $
{
Expires 30d;
}
Location ~ . * \. (Js | css )? $
{
Expires 12 h;
}
Access_log/home/wwwlogs/access. log access;
}
(2) java project configuration: file name www.111cn.net. conf
Here I have specified the configuration of a java project www.111cn.net
Server {
Listen 80;
Server_name www.111cn.net;
# Charset KOI8-R;
Access_log logs/dev/null;
Root/usr/local/tomcat6/webapps/quickbook /;
# Reverse proxy of the request to the tomcat application server
Location /{
Index. jsp index.html index.htm;
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_buffers 32 4 k;
Proxy_connect_timeout 3;
Proxy_send_timeout 30;
Proxy_read_timeout 30;
Proxy_pass http: // 127.0.0.1: 8080;
}
}
III. Summary
1. nginx puts the configuration of each sub-domain name in conf/vhost for independent processing.
2. The configuration files under each vhost take effect independently.
3. nginx only forwards requests to the backend application server.
4. Start in the following order
(1) start the mysql database
(2) start tomcat
(3) start nginx