windows下nginx安装、配置与使用_nginx

  目前国内各大门户网站已经部署了Nginx,如新浪、网易、腾讯等;国内几个重要的视频分享网站也部署了Nginx,如六房间、酷6等。新近发现Nginx 技术在国内日趋火热,越来越多的网站开始部署Nginx。

    相比apeach、iis,nginx以轻量级、高性能、稳定、配置简单、资源占用少等优势广受欢迎。

1)下载地址:

  http://nginx.org

2)启动

  解压至c:\nginx,运行nginx.exe(即nginx -c conf\nginx.conf),默认使用80端口,日志见文件夹C:\nginx\logs

3)使用

  http://localhost

4)关闭

  nginx -s stop 或taskkill /F /IM nginx.exe > nul

5)常用配置

   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;
 }
 }
}

  
  小提示:
  运行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

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

6)查看nginx进程

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

7)nginx常用命令

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

8)其它

  可以通过配置文件开启多个nginx工作进程,但同时只有其中一个nginx工作进程在工作,其他的阻塞等待。
  一个nginx工作进程最多同时可以处理1024个连接。
  nginx中需要共享内存的cache或者模块无法在windows下正常使用。
  不过,nginx官方正在改进,将来nginx会以服务的方式运行,使用 I/O completion ports代替select方法,使多个工作进程能并发工作。
  要使用nginx配合php-cgi使用,需要修改环境变量,否则,php-cgi运行一定次数就推出,需要重启,设置PHP_FCGI_MAX_REQUESTS这个变量为0即可。

  以上在win7上通过。

 8)nginx以windows服务形式启动

  1.下载微软两个工具:

    instsrv.exe srvay.exe

  2.执行命令:

    instsrv Nginxc:/nginx/srvany.exe

  3.配置Nginx的运行参数

  可以直接将配置导入到注册表

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 内置的module 很多没有,用Nginx -V 命令查看。

9)Nginx下部署mono+asp.net环境

  1、从Mono for Windows中提取FastCGI-Mono-Server

  2、Nginx nginx.conf 的配置:

复制代码 代码如下:

worker_processes  1;
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 提取出来,所有文件全部注册到 GAC(否则 Web 应用会找不到他们,当然你也可以直接放到 webapp/bin),然后解压到某个文件夹,这里假设为 D:/FastCGI-Mono-Server。

  之后我们就可以按下列命令运行 FastCGI:
  fastcgi-mono-server2 /socket=tcp:127.0.0.1:8000 /root="D:\www\yourwebapp" /applications=yourdomain.com:/:. /multiplex=True

  最后执行运行 Nginx 服务器,我们的 ASP.Net 程序就能脱离 IIS。

时间: 2024-08-30 05:17:15

windows下nginx安装、配置与使用_nginx的相关文章

Windows下MySQL安装配置方法图文教程_Mysql

Windows下的安装与配置MySQL详细步骤思路,分享给大家,供大家参考,具体内容如下 本文介绍Windows XP下的安装与配置. 要想在Windows中运行MySQL,需要: Ø 32位Windows操作系统,例如9x.Me.NT.2000.XP或Windows Server 2003. 基于Windows NT的操作系统(NT,2000,XP,2003),将MySQL服务器做为服务来运行.强烈建议使用基于Windows NT的操作系统. Ø TCP/IP协议支持(也许是所有数据库系统的基

windows下nginx+tomcat配置负载均衡的方法_nginx

目标:Nginx做为HttpServer,连接多个tomcat应用实例,进行负载均衡. 注:本例程以一台机器为例子,即同一台机器上装一个nginx和2个Tomcat且安装了JDK1.7. 1.安装Nginx 安装Nginx教程 2.配置两个Tomcat 在本机上配置两个Tomcat,分别为tomcat7-8081.tomcat7-8082. tomcat7-8081访问地址:http://localhost:8081,浏览显示内容:this is 8081 port tomcat7-8082访问

Windows下Redis安装配置教程_Redis

本文实例为大家分享了Windows下Redis的安装方法,供大家参考,具体内容如下 1.首先,Redis官方是支持Linux系统的,我这里不多说,需要的可以参考:http://www.jb51.net/article/96234.htm 2.Windows 64位下载地址:https://github.com/MSOpenTech/redis/releases 3.下载后的Redis解压到自己目录下面,解压后 4.这里你可以直接点击redis-server.exe启动,默认配置(无密码)启动 红

centos下Nginx安装配置步骤详解

nginx可以使用各平台的默认包来安装,本文是介绍使用源码编译安装,包括具体的编译参数信息. 正式开始前,编译环境gcc g++ 开发库之类的需要提前装好,这里默认你已经装好. ububtu平台编译环境可以使用以下指令 apt-get install build-essential apt-get install libtool centos平台编译环境使用如下指令 安装make: yum -y install gcc automake autoconf libtool make 安装g++:

Windows下PHP安装配置PEAR的方法

Windows下PHP PEAR安装:(1)下载go-pear.phpar到PHP安装目录  官方下载:http://pear.php.net/go-pear.phar(2)PEAR安装流程 ①执行php go-pear.phar  请选择local,因为system可能没有写入权限,然后选择yes ②选择同意修改php.ini ③安装php扩展 ④进入下载目录,引入php扩展即可使用.Linux下安装PEAR ①.下载pear包:  wget http://pear.php.net/go-pe

Windows下Redis安装配置简单教程_Redis

本文为大家分享了Redis安装教程,供大家参考,具体内容如下 1.安装Redis 通过以上路径下载后解压到具体文件夹,解压后的文件如下: 通过cmd切换到解压的文件夹目录,然后键入如下命令:redis-server --service-install redis.windows.conf既可以安装成功,在服务这里可以看到叫Redis的服务. 2.修改密码 在解压后的文件夹下面找到redis.windows.conf,使用文件编辑器进入编辑.找到requirepass,右边的foobared即是对

Windows下Nginx的安装与配置

Windows下Nginx的安装与配置 Nginx ("engine x") 是一款高性能的,轻量级的HTTP Web 服务器 和 反向代理服务器及电子邮件 IMAP/POP3/SMTP 代理服务器. Nginx 是由俄罗斯的程序设计师 Igor Sysoev 所开发,为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过四年多时间了,Igor 将源代码以类BSD许可证的形式发布. 自 Nginx 发布四年来,Nginx 已经因它的稳定性.丰富的功能集.示例配置

Windows下PHP安装路径配置错误导致Apache无法启动怎么解决?

  这篇文章主要介绍了Windows下PHP安装路径配置错误导致Apache无法启动的解决方法,本文可以说是一个引号引发的悲剧,需要的朋友可以参考下 LoadModule php5_module "C(/D):/Program Files/php5/php5apache2_2.dll" PHP安装路径引起的apache无法启动错误 今天给一同事的PC机安装部署web服务的时候,按同事要求把所有程序文件放到安装目录的program files下,于是我把apache安装到了c:progr

Windows下Nginx的启动、停止等命令&Nginx 配置多域名&windows下设置Nginx开机自动启动

Windows下Nginx的启动.停止等命令 在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动.停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍. 1.启动: C:\server\nginx-1.0.2>start nginx 或 C:\server\nginx-1.0.2>nginx.exe 注:建议使用第一种,第二种会使你的cmd窗口一直处于执行中,不能进行其他命令操作. 2.停止: C:\server\nginx-1.0.2>ngin