#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#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;
# }
#}
}
worker_processes
启动进程的数目,通常和cpu数目一致
error_log
全局错误日志
events{
use epoll;
worker_connections 1024;
}
events中配置工作模式以及连接数上限。
epoll是多路复用io中的一种方式,可以提高nginx性能;
worker_connections 就是单个启动进程worker_process最大并发链接数
并发总数 = worker_processes * worker_connections
http {
include mime.types;
default_type application/octet-stream;
设置mime类型,由mime.type定义,默认类型application/octet-stream
mime.type设置http响应的Content_Type
#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;
记录详细日志信息,logs/access.log是日志具体的存储位置
sendfile on;
设置nginx是否调用sendfile()方法输出文件(对于下载或者磁盘重负载的应用可以设置为off,来平衡磁盘和I/O处理速度)
#tcp_nopush on;
nginx在一个数据包中发送所有头文件,而不需要一个一个发送
#tcp_nodelay on;
设置nginx不要缓存数据
#keepalive_timeout 0;
keepalive_timeout 65;
设置连接超时时间
#gzip on;
开启压缩(gzip格式)
server {
listen 80;
监听端口,80是默认端口
server_name localhost;
定义使用localhost访问
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
定义网站根目录位置
index index.html index.htm;
设置首页索引文件名称
}
#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; 配置proxy_pass代理转发
#}
# 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服务器监听端口与地址
# 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;
# }
#}
}
upstream name{
server ip1:port weight = 1;
server ip2:port weight = 2;
server ip3:port weight = 3;
}
upstream 实现负载均衡,以weight(权重)方式分发,权重越大被分配到的几率越大
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
设置请求缓存,client_header_buffer_size是请求头缓冲区,超过了就会使用large_client_header_buffers