Windows下Nginx的安装与配置
Windows下Nginx的安装与配置
Nginx("enginex")是一款高性能的,轻量级的HTTPWeb服务器和反向代理服务器及电子邮件IMAP/POP3/SMTP代理服务器。
Nginx是由俄罗斯的程序设计师IgorSysoev所开发,为俄罗斯访问量第二的Rambler.ru站点开发的,它已经在该站点运行超过四年多时间了,Igor将源代码以类BSD许可证的形式发布。
自Nginx发布四年来,Nginx已经因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。Nginx超越Apache的高性能和稳定性,使得国内使用Nginx作为Web服务器的网站也越来越多。
目前国内各大门户网站已经部署了Nginx,如新浪、网易、腾讯等;新近发现Nginx技术在国内日趋火热,越来越多的网站开始应用部署Nginx。
一、首先去官网下载nginx1.0.11的Windows版本,官网下载:http://nginx.org/download/nginx-1.0.11.zip
下载到软件包后,解压nginx-nginx1.0.11.zip包到你喜欢的根目录,并将目录名改为nginx。
然后,执行下列操作:
cdnginx
startnginx
这样,nginx服务就启动了。打开任务管理器,查看nginx.exe进程,有二个进程会显示,占用系统资源,那是相当的少。然后再打开浏览器,输入http://127.0.0.1/就可以看到nginx的欢迎页面了,非常友好
nginx-sstop//停止nginx
nginx-sreload//重新加载配置文件
nginx-squit//退出nginx
二、接下来就是配置nginx的conf文件了。下面是我的配置:
#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pidlogs/nginx.pid;
events{
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;
#gzipon;
server{
listen80;
server_namelocalhost;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location~*software/(.*).*\.(jpg|rar)
{
expires21d;
rootd:/temp/;
access_logd:/temp/soft.3g.cn_nginx_s3gd-205.log;
proxy_storeon;
proxy_store_accessuser:rwgroup:rwall:rw;
proxy_temp_pathd:/temp/;
proxy_redirectoff;
proxy_set_headerHost112.25.10.140;
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://112.25.10.140:80;
}
}
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;
#}
#}
#HTTPSserver
#
#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;
#}
#}
}