网上说的很多配置都没有经过实战,当一个机器挂掉后就不能用了,这里给大家提供的是互联网应用实战用的配置
user root;
#工作的子进程数量(通常等于CPU数量或者2倍于CPU)
worker_processes 2;
#错误日志存放路径
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
#指定pid存放文件
pid logs/nginx.pid;
events {
#使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。
#允许最大连接数
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
fastcgi_intercept_errors on;
#定义日志格式
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log off;
access_log logs/access.log;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 75;
#include gzip.conf;
upstream tower{
server 172.16.5.65:8080;
server 172.16.5.65:8081;
}
server {
listen 8889;
server_name localhost;
location / {
proxy_connect_timeout 2;
proxy_send_timeout 2;
proxy_read_timeout 2;
proxy_pass http://tower/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout http_500 http_502 http_503 http_504 http_404;
client_max_body_size 200M;
}
error_page 404 /50x.html;
error_page 404 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}