nginx参数的详细介绍
nginx参数的详细介绍
最近公司的项目中涉及到旧老项目迁移,需要在nginx上做些配置,所以简单学习了下,好记性不如烂笔头,也许可以帮助到大家,
#开启进程数<=CPU数
worker_processes1;
#错误日志保存位置
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#进程号保存文件
#pidlogs/nginx.pid;
#等待事件
events{
#每个进程最大连接数(最大连接=连接数x进程数)
worker_connections1024;
}
http{
#文件扩展名与文件类型映射表
includemime.types;
#默认文件类型
default_typeapplication/octet-stream;
#日志文件输出格式这个位置相于全局设置
#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
#'$status$body_bytes_sent"$http_referer"'
#'"$http_user_agent""$http_x_forwarded_for"';
#请求日志保存位置
#access_loglogs/access.logmain;
#打开发送文件
sendfileon;
#tcp_nopushon;
#连接超时时间
#keepalive_timeout0;
keepalive_timeout65;
#打开gzip压缩
#gzipon;
#设定请求缓冲
client_header_buffer_size1k;
large_client_header_buffers44k;
#设定负载均衡的服务器列表
upstreamtomcat-servers{
#weigth参数表示权值,权值越高被分配到的几率越大
#max_fails当有#max_fails个请求失败,就表示后端的服务器不可用,默认为1,将其设置为0可以关闭检查
#fail_timeout在以后的#fail_timeout时间内nginx不会再把请求发往已检查出标记为不可用的服务器
#这里指定多个源服务器,ip:端口,80端口的话可写可不写
server127.0.0.1:8080weight=5max_fails=2fail_timeout=600s;
#server127.0.0.2:8080weight=3max_fails=2fail_timeout=600s;
}
#第一个虚拟主机
server{
#监听IP端口
listen80;
#主机名
server_namelocalhost;
#设置字符集
#charsetkoi8-r;
#本虚拟server的访问日志相当于局部变量
#access_loglogs/host.access.logmain;
#对本server"/"启用负载均衡
location/{
#root/root;#定义服务器的默认网站根目录位置
#indexindex.phpindex.htmlindex.htm;#定义首页索引文件的名称
proxy_passhttp://tomcat-servers;#请求转向tomcat-servers定义的服务器列表
#以下是一些反向代理的配置可删除.
#proxy_redirectoff;
#proxy_set_headerHost$host;
#proxy_set_headerX-Real-IP$remote_addr;
#proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
#client_max_body_size10m;#允许客户端请求的最大单文件字节数
#client_body_buffer_size128k;#缓冲区代理缓冲用户端请求的最大字节数,
#proxy_connect_timeout90;#nginx跟后端服务器连接超时时间(代理连接超时)
#proxy_send_timeout90;#后端服务器数据回传时间(代理发送超时)
#proxy_read_timeout90;#连接成功后,后端服务器响应时间(代理接收超时)
#proxy_buffer_size4k;#设置代理服务器(nginx)保存用户头信息的缓冲区大小
#proxy_buffers432k;#proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
#proxy_busy_buffers_size64k;#高负荷下缓冲大小(proxy_buffers*2)
#proxy_temp_file_write_size64k;#设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
location/upload{
aliase:/upload;
}
#设定查看Nginx状态的地址
location/NginxStatus{
stub_statuson;
access_logoff;
#allow192.168.0.3;
#denyall;
#auth_basic"NginxStatus";
#auth_basic_user_fileconf/htpasswd;
}
#error_page404/404.html;
#redirectservererrorpagestothestaticpage/50x.html
#定义错误提示页面
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.php${
#proxy_passhttp://127.0.0.1;
#}
#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
#location~\.php${
#roothtml;
#fastcgi_pass127.0.0.1:9000;
#fastcgi_indexindex.php;
#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
#includefastcgi_params;
#}
#denyaccessto.htaccessfiles,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/\.ht{
#denyall;
#}
}
#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration
#
#server{
#多监听
#listen8000;
#主机名
#listensomename:8080;
#server_namesomenamealiasanother.alias;
#location/{
#WEB文件路径
#roothtml;
#默认首页
#indexindex.htmlindex.htm;
#}
#}
#HTTPSserverHTTPSSSL加密服务器
#
#server{
#listen443;
#server_namelocalhost;
#sslon;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_timeout5m;
#ssl_protocolsSSLv2SSLv3TLSv1;
#ssl_ciphersHIGH:!aNULL:!MD5;
#ssl_prefer_server_cipherson;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!