Windows下Nginx的安装、启动、停止、配置

分类:服务器| 发布:佚名| 查看: | 发表时间:2014/6/24

1. 安装 Nginx

官方网站上面下载压缩包:http://nginx.net,下载后直接解压即可,这里解压缩到c:\nginx目录

2. 启动Nginx

命令行进入c:\nginx目录,运行nginx.exe,启动控制台窗口。默认启用80端口,可以在nginx.config文件修改端口。

访问:http://localhost,即可看到Welcome页面。

运行nginx -V可以查看该Win32平台编译版支持哪些模块。

3. 停止Nginx

直接关闭窗口,无法关闭Nginx,必须使用命令:

nginx -s stop

或者使用windows的taskkill命令:

taskkill /F /IM nginx.exe > nul

4. Ngnix常用配置

Nginx的所有配置都默认使用conf/nginx.conf文件,其地位相当于apache的httpd.conf文件 。当运行nginx.exe暗含运行了nginx -c conf\nginx.conf. 如果想使用自己定义的conf文件如my.conf,命令为nginx -c conf\my.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 /camnprWebRoot {
alias D:\programs\Apache2\htdocs\camnprWebRoot;
index index.html index.htm;
}
}
# 5.虚拟主机www.camnpr.com配置
server {
listen 80;
server_name www.camnpr.com;
access_log camnpr.com/logs/access.log;
location / {
index index.html;
root camnpr.com/htdocs;
}
}
}
365据说看到好文章不转的人,服务器容易宕机
原创文章如转载,请注明:转载自郑州网建-前端开发 http://camnpr.com/
本文链接:http://camnpr.com/server/1241.html