Windows环境下进行Nginx安装和配置的介绍
2014-08-10 16:56
706 查看
Nginx 是一个轻量级的高性能 Http WebServer,以事件驱动方式编写,因此相比 Apache 而言,Nginx 更加稳定、性能更好,而且配置简单,资源占用较低。
1. 安装 Nginx
从 v0.7.52 开始,Nginx 开始发布 Windows 版本的 Nginx,你可以在其官方网站上面下载:http://nginx.net
下载后直接解压即可,这里解压缩到c:\nginx目录。
2. 启动Nginx
命令行进入c:\nginx目录,运行nginx.exe,启动控制台窗口。默认启用80端口。用过Tomcat的人都希望能在控制台看到启动日志,nginx的日志却不得不查看logs目录下的相应log文件。
3. 访问欢迎html页
在浏览器中访问http://localhost,可以看到默认的欢迎页.
4. 停止Nginx
Ctrl+C没反应。于是关闭控制台窗口。可是再访问http://localhost依然有效。查看进程,发现nginx根本没有被关闭。因此如果想彻底关闭nginx,应该是
Command代码
nginx -s stop
请参考官方文档nginx/Windows
usage
或者使用windows的taskkill命令:
Command代码
taskkill /F /IM nginx.exe > nul
5. Ngnix常用配置
Nginx的所有配置都默认使用conf/nginx.conf文件,其地位相当于apache的httpd.conf文件 。当运行nginx.exe暗含运行了nginx -c 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下使用更方便。
1. 安装 Nginx
从 v0.7.52 开始,Nginx 开始发布 Windows 版本的 Nginx,你可以在其官方网站上面下载:http://nginx.net
下载后直接解压即可,这里解压缩到c:\nginx目录。
2. 启动Nginx
命令行进入c:\nginx目录,运行nginx.exe,启动控制台窗口。默认启用80端口。用过Tomcat的人都希望能在控制台看到启动日志,nginx的日志却不得不查看logs目录下的相应log文件。
3. 访问欢迎html页
在浏览器中访问http://localhost,可以看到默认的欢迎页.
4. 停止Nginx
Ctrl+C没反应。于是关闭控制台窗口。可是再访问http://localhost依然有效。查看进程,发现nginx根本没有被关闭。因此如果想彻底关闭nginx,应该是
Command代码
nginx -s stop
请参考官方文档nginx/Windows
usage
或者使用windows的taskkill命令:
Command代码
taskkill /F /IM nginx.exe > nul
5. Ngnix常用配置
Nginx的所有配置都默认使用conf/nginx.conf文件,其地位相当于apache的httpd.conf文件 。当运行nginx.exe暗含运行了nginx -c 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下使用更方便。
相关文章推荐
- 搭建Windows系统下php开发环境有很多种方式,比如LAMP的配置、php IDE和调试工具的选择等等。根据每个人喜好不同有很多配置方式。这里主要介绍的是利用XAMPP集成安装和配置apache、
- windows环境下nginx服务器的安装与配置
- windows环境下nginx服务器的安装与配置
- Windows 下 Nginx + PHP + MySQL 开发环境安装与配置
- windows平台上运行的unix模拟环境cygwin cygwin的安装配置与使用介绍
- Nginx 教程一:在windows环境下的安装、配置、使用以及设置为windows服务自启动
- Nodejs简单介绍以及在windows环境下安装与配置流程
- nginx安装配置+集群tomcat:Centos和windows环境
- windows 环境下面nginx的安装与配置
- Disconf介绍,源码下载,环境准备,安装,disconf-web使用和配置介绍,项目中进行配置,项目案例运行
- 关于windows环境下配置nginx的一些疑问
- Qt 4 开发环境的安装和配置(Windows)
- Windows 7 下安装和环境变量配置J2SE和TOMCAT6.0
- HOWTO install and setup Android NDK for Windows(Android NDK 开发环境安装和配置)
- HOWTO install and setup Android NDK for Windows(Android NDK 开发环境安装和配置)
- nginx环境下 XCache安装配置
- Windows 预安装环境配置文件-磁盘配置[DiskConfig]
- 跨平台GUI--Qt windows 开发环境安装配置(Eclipse CDT+ MinGW+QT) (转载)