一、 nginx软件拷贝

拷贝 nginx文件 到对应的服务目录中 如 e:/service/nginx
nginx文件地址: 链接:

二、 在项目盘中创建wwwroot 及 wwwconf

在日常开发的盘中添加 wwwroot 目录 (用于放置站点文件 )

并添加 wwwconf 目录 (用于放置 nginx站点配置)

三 、修改nginx配置文件

找到 e:/service/nginx/conf 目录下的 nginx.conf

在nginx.conf 中http代码块最后一行添加上 include e:/wwwconf/*.conf;

其作用主要是让nginx引入d:/wwwconf中所有的是 .conf 后缀的配置

四、 创建站点

先在e:/wwwconf中添加一个站点配置文件 如: project.com.conf
可以拷贝下面站点配置模板, 需要改的地发有:
server_name 后面的站点url地址 (可以配置多个域名 ,以空格隔开)
set $webroot  后面的是 站点对应的文件目录

其中的配置如:

server {
    listen       80;
    server_name  www.project.com project.com;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    set $webroot  e:/wwwroot/project.com;

    root $webroot;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;

    location / {
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

五 、站点映射

找到 c:\windows\system32\drivers\etc下的hosts文件 
添加 一条 127.0.0.1              www.project.com
其作用是访问 www.project.com 地址会重定向到本机地址

六 、nginx脚本配置

如在 e:/service 下创建一个bin目录 用于放置服务脚本
在 e:/service/bin 中创建nginx 服务脚本文件 nginx.bat
以下脚本需要注意如果目录不同则需要改变 脚本中的

====================================================
@echo off
rem 当前bat的作用

echo ==================begin========================

cls 
set nginx_path=e:
set nginx_dir=e:\service\nginx\
color 0a 
title nginx 管理程序控制面板

cls 

echo. 
echo. * nginx 管理程序 *  
echo. 

:menu 

echo. * nginx 进程list * 
tasklist|findstr /i "nginx.exe"

echo. 
echo. [1] 启动nginx 
echo. [2] 关闭nginx 
echo. [3] 重启nginx 
echo. [4] 退 出 
echo. 

echo.请输入选择项目的序号:
set /p id=
if "%id%"=="1" goto start 
if "%id%"=="2" goto stop 
if "%id%"=="3" goto restart 
if "%id%"=="4" exit
pause 

:start 
call :startnginx
goto menu

:stop 
call :shutdownnginx
goto menu

:restart 
call :shutdownnginx
call :startnginx
goto menu

:shutdownnginx
echo. 
echo.关闭nginx...... 
taskkill /f /im nginx.exe > nul
echo.ok,关闭所有nginx 进程
goto :eof

:startnginx
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" (
echo "start '' nginx.exe"
start "" nginx.exe
)
echo.ok
goto :eof

七、加入到脚本到系统环境变量中

配置系统环境变量:

八、运行效果

到此这篇关于windows系统安装配置nginx环境的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持。