user nobody [group]; //设置Nginx使用用户,因安全会创建一新用户,这个时候注意给新用户授权,不然 在下面用户创建日志的时候回权限不够报错,如果测试可直接使用root
worker_processes 8;//worker进程,一般配置为电脑核数,后面预估最大连接:worker_process*worder_connections
error_log logs/error.log debug/notice/info/error/crit;//指定Nginx错误日志的存储目录和日志等级,一般生产设置为error或crit,可以在server和http中配置具体服务的错误日志, 分开管理查看,关闭错误日志可使用: error_log /dev/null crit;
pid logs/nginx.pid;//编译的时候指定的进程文件,默认位置在log/
worker_connections 1024; //理论单个worker最大连接数,新装的系统一般默认是1024,即系统最大打开文件数,查看命名:ulimit -n;可以通过如下方式修改:
在/etc/security/limits.conf最后增加*soft nofile 65535 *hard nofile 65535 *soft nproc 65535 *hard nproc 65535
accept_mutex:on(default);//Nginx处理请求互斥锁的开闭,保证连接的处理顺序,在访问量大的情况下,可以修改成off
由于浏览器默认打开两个连接到服务器,Nginx也要发两个到服务器,真正请求连接数为worker_process* worder_connections/4
}
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"';
access_log logs/access.log main buffer=32k //使用上述日志格式并缓冲32k;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream mytest.com{ //配置后端服务器路径及权重
server 127.0.0.1:8080 weight=5;
}
server {
listen 80;
server_name localhost;
charset koi8-r;
access_log logs/host.access.log main;
location ~* .*\.(jpg|jpeg|gif|png|swf|ico)$ { //配置静态文件访问路径,不经过后端服务器处理,实现动静分离
root /usr/local/tomcat/tomcat8/webapps/ROOT/;}
proxy_pass http://mytest.com;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}