Windows下Nginx的配置及配置文件部分介绍
一、在官网下载nginx的Windows版本,官网下载:http://nginx.org/download/
选择你自己想要的版本下载,解压nginx(例如nginx-1.6.3)包到你的window盘里的目录上。
执行下列操作:(需要记住的,会经常用到)
nginx-sstop         //停止nginx
nginx-sreload      //重新加载配置文件
nginx-squit         //退出nginx
二、接下来就是配置nginx的conf文件了。nginx需要配置的东西也就是在conf文件中,现在介绍下了解下conf文件的配置:
#usernobody;
worker_processes2;#进程数,初始可设置为cpu总核数
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pidlogs/nginx.pid;#用于管理nginx进程
events{
worker_connections1024;#单个worker进程最大连接数
}
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;#连接超时时间,单位是秒
#gzipon;
server{
listen8089;#连接的端口号
server_namelocalhost;
autoindexon;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
#下面的就是你接收传输文件的格式要求了,根据你的需要来用,下面我使用来接收图片(jpg...)
location~.*\.(gif|jpg|jpeg|png|bmp)${
expires24h;#客户端缓存上述静态数据
rootC:/resources/images/;#文件路径
access_logC:/nginx-1.6.3/logs/log_test.log;
proxy_storeon;
proxy_store_accessuser:rwgroup:rwall:rw;
proxy_temp_pathC:/resources/images/;#文件路径
proxy_redirectoff;
#autoindexon;
proxy_set_headerHost127.0.0.1;#填写你的ip
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
client_max_body_size10m;
client_body_buffer_size1280k;
proxy_connect_timeout900;
proxy_send_timeout900;
proxy_read_timeout900;
proxy_buffer_size400k;
proxy_buffers40320k;
proxy_busy_buffers_size640k;
proxy_temp_file_write_size640k;
if(!-e$request_filename)
{
proxy_passhttp://127.0.0.1:8089;
}
}
#下面是我拿来传输mp3格式的配置
location~*.(mp3)${
expires24h;
rootC:/resources/voice/;#文件路径
proxy_storeon;
proxy_store_accessuser:rwgroup:rwall:rw;
proxy_temp_pathC:/resources/voice/;#文件路径
proxy_redirectoff;
proxy_set_headerHost127.0.0.1;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
client_max_body_size10m;
client_body_buffer_size1280k;
proxy_connect_timeout900;
proxy_send_timeout900;
proxy_read_timeout900;
proxy_buffer_size40k;
proxy_buffers40320k;
proxy_busy_buffers_size640k;
proxy_temp_file_write_size640k;
if(!-e$request_filename)
{
proxy_passhttp://127.0.0.1:8089;
}
}
location/{
roothtml;
indexindex.htmlindex.htm;
}
#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/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}
#下面是配置https
#HTTPSserver
#
#server{
#listen443ssl;
#server_namelocalhost;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_cacheshared:SSL:1m;
#ssl_session_timeout5m;
#ssl_ciphersHIGH:!aNULL:!MD5;
#ssl_prefer_server_cipherson;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}
}
3.注意事项
会遇到的问题:
1.配置完conf后,你启动nginx启动不了,说明是你conf文件配置有错误,你需要回去检查下。比如{}少了,文件路径名不对等等。
2.有时会根据需要用到http和https 整个配置文件你只需要配置到http{ }里面和https{}里面的东西就行。
以上所述是小编给大家介绍的Windows下Nginx的配置及配置文件部分介绍,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
