nginx配置文件(反向代理+集群+动静分离)
1、nginx纯反向代理配置(nginx.conf):
#user nobody;
worker_processes 4;
error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events{
#use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
client_max_body_size 300m;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
#gzip_types application/xml;
gzip_vary on;
proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 5;
proxy_send_timeout 60;
proxy_read_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
server {
listen 9000;
server_name localhost;
root "E:\WEB";
index index.html index.htm;
location /Learning {
proxy_pass http://localhost:8081/Learning;
}
location /WebFiles/ {
proxy_pass http://182.92.159.70/WebFiles/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
2、nginx单点代理+动静分离:
#user nobody;
worker_processes 4;
error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events{
#use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
client_max_body_size 300m;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
#gzip_types application/xml;
gzip_vary on;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 5;
proxy_send_timeout 60;
proxy_read_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
server {
listen 9000;
server_name localhost;
root "E:\WEB";
index index.html index.htm;
location / {
location ~ \.(jsp|action)$ {
proxy_pass http://localhost:8081;
}
location ~ \.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|mp3|GIF|JPG|JPEG|PNG|BMP)$ {
expires 30d;
}
location ~ \.(js|css|xml)?$ {
expires 1h;
}
}
location /Learning/webservice/ {
proxy_pass http://localhost:8081;
}
location /WebFiles/ {
proxy_pass http://182.92.159.70/WebFiles/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3、nginx+tomcat集群+故障转移+动静分离:
#user nobody;
worker_processes 4;
error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events{
#use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
client_max_body_size 300m;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
#gzip_types application/xml;
gzip_vary on;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 5;
proxy_send_timeout 60;
proxy_read_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
upstream myserver {
ip_hash;
server localhost:8081;
server localhost:8082;
}
server {
listen 9000;
server_name localhost;
root "E:\WEB";
index index.html index.htm;
location / {
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
location ~ \.(jsp|action)$ {
proxy_pass http://myserver;
}
location ~ \.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|mp3|GIF|JPG|JPEG|PNG|BMP)$ {
expires 30d;
}
location ~ \.(js|css|xml)?$ {
expires 1h;
}
}
location /Learning/webservice/ {
proxy_pass http://localhost:8081;
}
location /WebFiles/ {
proxy_pass http://182.92.159.70/WebFiles/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}