windows下安装以及配置nginx

http://jingyan.baidu.com/article/f3e34a12a9c1c3f5eb6535d4.html

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;
   }
   }
  }
  
  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下使用更方便。

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 配置以及常用命令的更多相关文章

  1. nginx日常维护常用命令

    http://www.jb51.net/article/47750.htm 一.简明nginx常用命令 1. 启动 Nginx poechant@ubuntu:sudo ./sbin/nginx 2. ...

  2. (Linux环境Kafka集群安装配置及常用命令

    Linux环境Kafka集群安装配置及常用命令 Kafka 消息队列内部实现原理 Kafka架构 一.下载Kafka安装包 二.Kafka安装包的解压 三.设置环境变量 四.配置kafka文件 4.1 ...

  3. nginx实战操作(常用命令及配置)

    1. nginx介绍 2. nginx常用命令 验证配置是否正确: nginx -t 查看Nginx的详细的版本号:nginx -V 查看Nginx的简洁版本号:nginx -v 启动Nginx:st ...

  4. nginx 安装配置和常用命令

    基本环境:CentOS 1. 下载 nginx [root@localhost ~]# cd Downloads/ [root@localhost Downloads]# wget http://ng ...

  5. Nginx安装及常用命令

    一.选定源码目录 cd /usr/local/src 可以是任何目录,本文选定的是/usr/local/src 二.安装依赖库 yum install gcc yum install pcre-dev ...

  6. supervisor 安装、配置、常用命令

    前言 在 web 应用部署到线上后,需要保证应用一直处于运行状态,在遇到程序异常.报错等情况,导致 web 应用终止时,需要保证程序可以立刻重启,继续提供服务. 所以,就需要一个工具,时刻监控 web ...

  7. Git的配置及常用命令

    Git配置 git config --global user.name "<username>" git config --global user.email &quo ...

  8. Java学习系列(一)Java的运行机制、JDK的安装配置及常用命令详解

    俗话说:“十五的月亮十六圆”.那学习是不是也是如此呢?如果把月亮看成是我们的愿望,那十五便是我们所处的“高原期”,坚持迈过这个坎,我相信你的愿望终究会现实的.记得马云曾说:今天很残酷,明天更残酷,后天 ...

  9. 【Linux 操作系统】vim编辑器配置及常用命令

    最近工作不安分, 没有了刚入行时候的锐气, 不知道什么时候开始懈怠起来, 周末在电脑旁边看新闻, 搞笑图片, 追美剧, 一坐就是一天, 很是空虚. 我需要摆脱这种状态, 正好想学习一下安卓底层, An ...

随机推荐

  1. LRU缓存算法 - C++版

    LRU是Least Recently Used的缩写,意思是最近最少使用,它是一种Cache替换算法. 实现思路: hashtable + 双向链表 时间复杂度: 插入,查找,删除:O(1) 空间使用 ...

  2. 文成小盆友python-num17 - django基础

    一.首先了解web应用的本质 对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. 下面利用socket实现一个简单的web框架: #!/usr/b ...

  3. 如何进行fragment中的来回切换?

    本文选自StackOverflow(简称:SOF)精选问答汇总系列文章之一,本系列文章将为读者分享国外最优质的精彩问与答,供读者学习和了解国外最新技术,本文为大家讲解如何进行fragment中的来回切 ...

  4. Qt编程之QString 处理换行

    由于之间写过的一篇文章,Unix,windows,Mac里面的换行符不一样,导致处理也不一样,我现在要用QString以行分割(读取的文本文件的里面有换行符).所以要通吃这三种换行符 http://w ...

  5. MFC之按键消息(长按处理)

    想要实现长按键的一些控制,查了查可以通过捕获键盘事件,然后处理按键时需要进行的操作.下面简单的实现左右按键界面更新数值加减.  1. 重载PreTranslateMessage(MSG* pMsg)函 ...

  6. SQLServer Alter 修改表的列名的解决

    解决:在SQLServer中修改表的列名,可以调用存储过程sp_rename. [sql]use Test;--使用数据库  sp_rename 'd_s_t.avg_grade','avg_g',' ...

  7. HDU4742----Pinball Game 3D(三维LIS、CDQ分治)

    题意:三维空间内 n个小球,对应坐标(x,y,z).输出LIS的长度以及方案数. 首先可以先按x排序,先降低一维,然后 剩下y .z,在y上进行CDQ分治,按y的大小用前面的更新后面的.z方向离散化之 ...

  8. tomcat主目录

    简单显示天气预报js 代码

  9. libvirtVirsh

    virsh基于不同协议远程连接libvirt drivers(Hypervisors) 基于OS系统账号ssh登陆

  10. Eclipse默认配色的恢复方法

    Eclipse默认配色的恢复方法 很多搞开发的同学一开始不喜欢默认的eclipse白底配色,去网上千辛万苦搜到了很多黑底暗色的各种eclipse配色然后import上了,之后却发现并不适合自己,想找默 ...