nginx配置:
user www www;
worker_processes 2;
worker_cpu_affinity 00000001 00000010;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 10240;
events
{
use epoll;
worker_connections 10240;
}
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 www {
server 192.168.5.50:8080 max_fails=2 fail_timeout=30s;
server 192.168.5.51:8080 max_fails=2 fail_timeout=30s;
ip_hash;
}
include /usr/local/nginx/vhost/*.conf;
}
新建
/usr/local/nginx/vhost/vhost.conf
server {
listen 80;
server_name localhost;
index index.html index.htm;
root /web/;
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://www;
expires 3d;
}
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://www;
access_log /usr/local/nginx/logs/access.log main;
error_log /usr/local/nginx/logs/error.log crit;
}
}
~