First, the experimental environment:
System version: centos6.5 64
Nginx Version: nginx-1.2.6
JDK version: jdk-8u45-linux-x64.rpm
Tomcat version: tomcat-7.0.62.tar.gz
Second, Nginx installation:
Yum Install Pcre-devel pcre-y
Yum-y Install OpenSSL Openssl-devel
Cd/usr/src
WGet http://nginx.org/download/nginx-1.2.6.tar.gz
Tar-xzf nginx-1.2.6.tar.gz
./configure--user=www--group=www--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module
Make&&make Install
Third, configure Nginx
/usr/sbin/groupadd-f www
/usr/sbin/useradd-g www www
Mkdir-p/data/www
Cd/usr/local/nginx/conf
MV Nginx.conf Nginx.bak
VI nginx.conf
user www www;worker_processes 8;worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;pid /usr/local/nginx/logs/ nginx.pid;worker_rlimit_nofile 102400;events{use epoll;worker_connections 102400;} http{ include mime.types; default_type application/octet-stream; fastcgi_intercept_errors on; charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 4k; large_client_header_buffers 4 32k; client_max_body_size 300m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; client_body_buffer_size 512k; proxy_connect_ timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_ types text/plain application/x-javascript text/css application/xml; gzip_vary on;log_format main ' $http _x_forwarded_for - $remote _user [$time _local] "$request" " ' $status $body _bytes_sent "$http _referer" ' "$http _user_agent" $request _time $remote _addr '; upstream apachephp { server 172.31.82.178:8080; // This is Agent nginx# server 192.168.1.133 weight=1 max_fails=2 . fail_timeout=30s;} include vhosts.conf;}
Create a vhosts.conf below the sibling directory
Vim vhosts.conf
##### #www .a.comserver { listen 80; server_name 172.31.82.178; index index.html index.htm; location / { proxy_next_upstream http_502 http_504 error timeout invalid_ header; proxy_set_header host $host; proxy_set_header X-Real-IP $remote _addr; proxy_set_header X-Forwarded-For $proxy _add_x_ forwarded_for; proxy_pass http://apachephp; expires 3d; } &nbSp; location ~ .*\. (php|jsp|cgi)? $ { proxy_set_header Host $host; proxy_set_header x-real-ip $remote _addr; proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; proxy_ Pass http://apachephp; } location ~ .*\. (HTML|HTM|GIF|JPG|JPEG|BMP|PNG|ICO|TXT|JS|CSS) $ { root / data/www/; //here is a static picture catalog expires 3d; } access_log /usr/local/nginx/logs/access.log main; error_log /usr/local/nginx/logs/Error.log crit;}
Check that the Nginx configuration file is properly configured, indicating that OK and successful are correct
#/usr/local/nginx/sbin/nginx-t
Nginx:the configuration file/usr/local/nginx/conf/nginx.conf syntax is OK
Nginx:configuration file/usr/local/nginx/conf/nginx.conf Test is successful
Start Nginx Service
/usr/local/nginx/sbin/nginx
To see if the Nginx process is started
Ps-ef |grep Nginx
Iv. installation of Tomcat
Installing the JDK
RPM-IVH jdk-8u45-linux-x64.rpm
To configure a Java environment variable:
Export Java_home=/usr/java/jdk1.8.0_45export path= $JAVA _home/bin: $PATHexport classpath=.: $JAVA _home/lib/dt.jar:$ Java_home/lib/tools.jar
Source/etc/profile
Tar zxvf apache-tomcat-7.0.62.tar.gz
MV Apache-tomcat-7.0.62/usr/local/tomcat
To start Tomcat:
/usr/local/tomcat/bin/startup.sh
To see if Tomcat is started:
Ps-ef |grep Tomcat
V. Test static and dynamic separation:
Upload some pictures in the/data/www/directory
Then use the ip+ image name in the browser to test whether the image can be paged
This article is from the "david0512" blog, make sure to keep this source http://gjr0512.blog.51cto.com/6518687/1754224
Nginx Static and dynamic separation