windows下nginx安裝、配置與使用
目前國內(nèi)各大門戶網(wǎng)站已經(jīng)部署了Nginx,如新浪、網(wǎng)易、騰訊等;國內(nèi)幾個(gè)重要的視頻分享網(wǎng)站也部署了Nginx,如六房間、酷6等。新近發(fā)現(xiàn)Nginx 技術(shù)在國內(nèi)日趨火熱,越來越多的網(wǎng)站開始部署Nginx。
相比apeach、iis,nginx以輕量級(jí)、高性能、穩(wěn)定、配置簡單、資源占用少等優(yōu)勢廣受歡迎。
1)下載地址:
2)啟動(dòng)
解壓至c:\nginx,運(yùn)行nginx.exe(即nginx -c conf\nginx.conf),默認(rèn)使用80端口,日志見文件夾C:\nginx\logs
3)使用
4)關(guān)閉
nginx -s stop 或taskkill /F /IM nginx.exe > nul
5)常用配置
C:\nginx\conf\nginx.conf,使用自己定義的conf文件如my.conf,命令為nginx -c conf\my.conf
常用配置如下:
http {
server {
#1.偵聽80端口
listen 80;
location / {
# 2. 默認(rèn)主頁目錄在nginx安裝目錄的html子目錄。
root html;
index index.html index.htm;
# 3. 沒有索引頁時(shí),羅列文件和子目錄
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
# 4.指定虛擬目錄
location /tshirt {
alias D:\programs\Apache2\htdocs\tshirt;
index index.html index.htm;
}
}
# 5.虛擬主機(jī)www.emb.info配置
server {
listen 80;
server_name www.emb.info;
access_log emb.info/logs/access.log;
location / {
index index.html;
root emb.info/htdocs;
}
}
}
小提示:
運(yùn)行nginx -V可以查看該Win32平臺(tái)編譯版支持哪些模塊。我這里的結(jié)果為:
Log代碼
TLS SNI support enabled
configure arguments:
--builddir=objs.msvc8
--crossbuild=win32
--with-debug --prefix=
--conf-path=conf/nginx.conf
--pid-path=logs/nginx.pid
--http-log-path=logs/access.log
--error-log-path=logs/error.log
--sbin-path=nginx.exe
--http-client-body-temp-path=temp/client_body_temp
--http-proxy-temp-path=temp/proxy_temp
--http-fastcgi-temp-path=temp/fastcgi_temp
--with-cc-opt=-DFD_SETSIZE=1024
--with-pcre=objs.msvc8/lib/pcre-7.9
--with-openssl=objs.msvc8/lib/openssl-0.9.8k
--with-openssl-opt=enable-tlsext
--with-zlib=objs.msvc8/lib/zlib-1.2.3
--with-select_module
--with-http_ssl_module
--with-http_realip_module
--with-http_addition_module
--with-http_sub_module
--with-http_dav_module
--with-http_stub_status_module
--with-http_flv_module
--with-http_gzip_static_module
--with-http_random_index_module
--with-http_secure_link_module
--with-mail
--with-mail_ssl_module
--with-ipv6
顯然,最經(jīng)常用的memcache, rewrite模塊都沒在其中,因此該win32編譯版本僅能供基本開發(fā)測試使用,對(duì)于產(chǎn)品平臺(tái),應(yīng)該重新編譯自己想要的win32版本,或者在linux下使用更方便。
6)查看nginx進(jìn)程
tasklist /fi "imagename eq nginx.exe",如下顯示:
映像名稱 PID 會(huì)話名 會(huì)話# 內(nèi)存使用
========================= ======== ================ =========== ============
nginx.exe 8944 Console 1 5,128 K
nginx.exe 6712 Console 1 5,556 K
7)nginx常用命令
nginx -s stop 強(qiáng)制關(guān)閉
nginx -s quit 安全關(guān)閉
nginx -s reload 改變配置文件的時(shí)候,重啟nginx工作進(jìn)程,來時(shí)配置文件生效
nginx -s reopen 打開日志文件
8)其它
可以通過配置文件開啟多個(gè)nginx工作進(jìn)程,但同時(shí)只有其中一個(gè)nginx工作進(jìn)程在工作,其他的阻塞等待。
一個(gè)nginx工作進(jìn)程最多同時(shí)可以處理1024個(gè)連接。
nginx中需要共享內(nèi)存的cache或者模塊無法在windows下正常使用。
不過,nginx官方正在改進(jìn),將來nginx會(huì)以服務(wù)的方式運(yùn)行,使用 I/O completion ports代替select方法,使多個(gè)工作進(jìn)程能并發(fā)工作。
要使用nginx配合php-cgi使用,需要修改環(huán)境變量,否則,php-cgi運(yùn)行一定次數(shù)就推出,需要重啟,設(shè)置PHP_FCGI_MAX_REQUESTS這個(gè)變量為0即可。
以上在win7上通過。
8)nginx以windows服務(wù)形式啟動(dòng)
1.下載微軟兩個(gè)工具:
instsrv.exe srvay.exe
2.執(zhí)行命令:
instsrv Nginxc:/nginx/srvany.exe
3.配置Nginx的運(yùn)行參數(shù)
可以直接將配置導(dǎo)入到注冊(cè)表
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/NGINX/Parameters]
"Application"="C://nginx//nginx.exe"
"AppParameters"=""
"AppDirectory"="C://nginx//"
注意:windows 下的Nginx 內(nèi)置的module 很多沒有,用Nginx -V 命令查看。
9)Nginx下部署mono+asp.net環(huán)境
1、從Mono for Windows中提取FastCGI-Mono-Server
2、Nginx nginx.conf 的配置:
error_log logs/error-debug.log info;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type text/plain;
sendfile on;
keepalive_timeout 65;
index index.html index.htm;
server {
listen 80;
server_name yourdomain.com;
index index.aspx default.aspx;
location / {
root D:\www/yourwebapp;
fastcgi_pass 127.0.0.1:8000;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
}
將上面的 FastCGI-Mono-Server 提取出來,所有文件全部注冊(cè)到 GAC(否則 Web 應(yīng)用會(huì)找不到他們,當(dāng)然你也可以直接放到 webapp/bin),然后解壓到某個(gè)文件夾,這里假設(shè)為 D:/FastCGI-Mono-Server。
之后我們就可以按下列命令運(yùn)行 FastCGI:
fastcgi-mono-server2 /socket=tcp:127.0.0.1:8000 /root="D:\www\yourwebapp" /applications=yourdomain.com:/:. /multiplex=True
最后執(zhí)行運(yùn)行 Nginx 服務(wù)器,我們的 ASP.Net 程序就能脫離 IIS。
以上就是本文的全部內(nèi)容,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Nginx Rewrite規(guī)則與使用介紹和技巧實(shí)例
這篇文章主要介紹了Nginx Rewrite規(guī)則與使用介紹和技巧實(shí)例,本文講解了正則表達(dá)式匹配、文件及目錄匹配、flag標(biāo)記、Nginx Rewrite相關(guān)指令等內(nèi)容,需要的朋友可以參考下2015-01-01Nginx服務(wù)器中限制連接數(shù)與限制請(qǐng)求的模塊配置教程
這篇文章主要介紹了Nginx服務(wù)器中限制連接數(shù)與限制請(qǐng)求的模塊配置教程,分別為limit conn模塊與limit req模塊的相關(guān)用法講解,需要的朋友可以參考下2016-01-01nginx 502、413和404錯(cuò)誤原因排查和解決辦法總結(jié)
這篇文章主要給大家介紹了NGINX 502錯(cuò)誤排查,辦法總結(jié),Nginx 413錯(cuò)誤的排查以及Nginx 400錯(cuò)誤排查,文中通過代碼示例給出了詳細(xì)的排查方法和解決方案,需要的朋友可以參考下2023-12-12詳解nginx+php執(zhí)行請(qǐng)求的工作原理
這篇文章主要介紹了詳解nginx+php執(zhí)行請(qǐng)求的工作原理,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-02-02