您的位置:首页 > 运维架构 > Nginx

window nginx虚拟主机(多站点)配置教程

2012-12-04 10:28 274 查看
nginx 目录结构

nginx-0.8.54 
│ nginx.exe //主程序 
│ 
├─conf 
│ │ fastcgi_params 
│ │ koi-utf 
│ │ koi-win 
│ │ mime.types 
│ │ nginx.conf //核心配置文件 
│ │ win-utf 
│ │ 
│ └─vhost //虚拟主机目录 
│ www.uctest.conf 
│ news.uctest.conf 
│ 
├─contrib 
│ │ geo2nginx.pl 
│ │ README 
│ │ 
│ └─unicode2nginx 
│ koi-utf 
│ unicode-to-nginx.pl 
│ win-utf 
│ 
├─docs 
│ CHANGES 
│ CHANGES.ru 
│ LICENSE 
│ OpenSSL.LICENSE 
│ PCRE.LICENCE 
│ README 
│ zlib.LICENSE 
│ 
├─html 
│ 50x.html 
│ index.html 
│ 
├─logs 
│ access.log 
│ error.log 
│ nginx.pid 
│ 
└─temp 
├─client_body_temp 
├─fastcgi_temp 
└─proxy_temp

进入conf文件夹,将内部的server配置段提取单独放在一个文件里,存到了conf/vhost下,以方便配置多个虚拟主机。
并在nginx.conf里http配置段内添加了一行 include vhost/*.conf;用来读取vhost下的虚拟主机配置。
  修改后的nginx.conf 配置文件

#user nobody; 
worker_processes 1; 
#error_log logs/error.log; 
#error_log logs/error.log notice; 
#error_log logs/error.log info; 
#pid logs/nginx.pid; 
events { 
worker_connections 1024; 
} 
http { 
include mime.types; 
default_type application/octet-stream; 
sendfile on; 
keepalive_timeout 65; 
#gzip on; 
include vhost/*.conf; #加载vhost目录下的虚拟主机配置文件 
}

修改vhost 下的虚拟主机配置文件以www.uctest.com为例,在server_name 后添加网站域名,可添加多个,多个之间“空格”分开;
root 节用来配置网站文件路径,路径格式:d:/www/www.uctest.com;

server { 
listen 80; 
server_name download-bj.tv0714.com; #可配置多个主机头 
location / { 
root d:/www/www.uctest.com; #网站文件路径 
index index.htm index.html; 
} 
error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
root html; 
} 
}

管理脚本:请打开http://www.cnblogs.com/leleroyn/archive/2010/07/08/1773388.html这里参观。下面附上一份:

Rem 提供Windows下nginx的启动,重启,关闭功能 
cls 
@ECHO OFF 
SET NGINX_PATH=E: 
SET NGINX_DIR=E:\nginx-0.8.40\ 
color 0a 
TITLE Nginx 管理程序 Power By Ants (http://leleroyn.cnblogs.com) 
GOTO MENU 
:MENU 
CLS 
ECHO. 
ECHO. * * * * Nginx 管理程序 Power By Ants (http://leleroyn.cnblogs.com) * * * 
ECHO. * * 
ECHO. * 1 启动Nginx * 
ECHO. * * 
ECHO. * 2 关闭Nginx * 
ECHO. * * 
ECHO. * 3 重启Nginx * 
ECHO. * * 
ECHO. * 4 退 出 * 
ECHO. * * 
ECHO. * * * * * * * * * * * * * * * * * * * * * * * * 
ECHO. 
ECHO.请输入选择项目的序号: 
set /p ID= 
IF "%id%"=="1" GOTO cmd1 
IF "%id%"=="2" GOTO cmd2 
IF "%id%"=="3" GOTO cmd3 
IF "%id%"=="4" EXIT 
PAUSE 
:cmd1 
ECHO. 
ECHO.启动Nginx...... 
IF NOT EXIST %NGINX_DIR%nginx.exe ECHO %NGINX_DIR%nginx.exe不存在 
%NGINX_PATH% 
cd %NGINX_DIR% 
IF EXIST %NGINX_DIR%nginx.exe start %NGINX_DIR%nginx.exe 
ECHO.OK 
PAUSE 
GOTO MENU 
:cmd2 
ECHO. 
ECHO.关闭Nginx...... 
taskkill /F /IM nginx.exe > nul 
ECHO.OK 
PAUSE 
GOTO MENU 
:cmd3 
ECHO. 
ECHO.关闭Nginx...... 
taskkill /F /IM nginx.exe > nul 
ECHO.OK 
GOTO cmd1 
GOTO MENU

这样,总体就非常方便了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: