PHP · 2014年8月4日 0

nginx资料整理

How to install Nginx on Windows

http://www.nginxtips.com/how-to-install-nginx-in-windows/

 

nginx: download:windows版本–http://nginx.org/en/download.html

下载windows的nginx压缩包,解压运行(nginx.exe)。

端口占用导致win7下无法启动nginx服务器,启动(nginx.exe)窗口一闪而过,没有提示出来链接网络。

修改nginx/conf/nginx.conf中

server {
listen 8011;(修改端口号就行了)

……}

再次运行(nginx.exe)是不是启动成功 输入http://localhost:8011/

出现:

Welcome to nginx!

恭喜你,nginx启动成功了!

配置nginx到环境变量(主要下面命令要用,否则输入下面命令要带上nginx.exe的全路径)

nginx常用命令

nginx -s stop 强制关闭
nginx -s quit 安全关闭
nginx -s reload 改变配置文件的时候,重启nginx工作进程,来时配置文件生效
nginx -s reopen 打开日志文件

常用配置

C:\nginx\conf\nginx.conf,使用自己定义的conf文件如my.conf,命令为nginx -c conf\my.conf

常用配置如下:
Nginx.conf代码
http {
server {
#1.侦听80端口
listen 80;
location / {
# 2. 默认主页目录在nginx安装目录的html子目录。
root html;
index index.html index.htm;
# 3. 没有索引页时,罗列文件和子目录
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
# 4.指定虚拟目录
location /tshirt {
alias D:\programs\Apache2\htdocs\tshirt;
index index.html index.htm;
}
}
# 5.虚拟主机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;
}
}
}

http {
server {
#1.侦听80端口
listen 80;
location / {
# 2. 默认主页目录在nginx安装目录的html子目录。
root html;
index index.html index.htm;
# 3. 没有索引页时,罗列文件和子目录
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
# 4.指定虚拟目录
location /tshirt {
alias D:\programs\Apache2\htdocs\tshirt;
index index.html index.htm;
}
}
# 5.虚拟主机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;
}
}
}

小提示:
运行nginx -V可以查看该Win32平台编译版支持哪些模块。我这里的结果为:
Log代码
nginx version: nginx/0.7.65
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

nginx version: nginx/0.7.65
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

显然,最经常用的memcache, rewrite模块都没在其中,因此该win32编译版本仅能供基本开发测试使用,对于产品平台,应该重新编译自己想要的win32版本,或者在linux下使用更方便。

查看nginx进程

tasklist /fi “imagename eq nginx.exe”,如下显示:
映像名称                       PID 会话名              会话#       内存使用
========================= ======== ================ =========== ============
nginx.exe                     8944 Console                    1      5,128 K
nginx.exe                     6712 Console                    1      5,556 K

Share this: