Nginx之windows下搭建

去nginx.org下载nginx 以nginx-1.8.1为例解压到D盘nginx-1.8.1目录

假设NGINX_HOME为D:\nginx-1.8.1

3种启动途径:

一、双击nginx.exe图标,可见黑窗口一闪而过,启动完毕。

二、命令行到nginx目录,输入nginx启动。(注,此方式命令行窗口无任何提示,且被锁定)

三、命令行到nginx目录,输入start nginx启动,此方式不锁定

命令汇总

nginx -s reload|reopen|stop|quit  #重新加载配置|重启|停止|退出 nginx

nginx -t   #测试配置是否有语法错误

nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

-?,-h           : 打开帮助信息

-v              : 显示版本信息并退出

-V              : 显示版本和配置选项信息,然后退出

-t              : 检测配置文件是否有语法错误,然后退出

-q              : 在检测配置文件期间屏蔽非错误信息

-s signal       : 给一个 nginx 主进程发送信号:stop(停止), quit(退出), reopen(重启), reload(重新加载配置文件)

-p prefix       : 设置前缀路径(默认是:/usr/local/Cellar/nginx/1.2.6/)

-c filename     : 设置配置文件(默认是:/usr/local/etc/nginx/nginx.conf)

-g directives   : 设置配置文件外的全局指令

浏览地址http://localhost,即可访问其默认页面,即映射到NGINX_HOME/html/index.html

在NGINX_HOME下新建一个MySites文件夹 再新建两个Test和First文件夹 并加入index.html文件

打开NGINX_HOME/conf/nginx.conf 增加下面配置

    server {
        listen       9000;
        server_name  localhost;

        location / {
            root   MySites/test;
            index  index.html index.htm;
        }
    }
	
    server {
        listen       80;
        server_name  first1.zns.com  first2.zns.com;

        location / {
            root   MySites/first;
            index  index.html index.htm;
        }
    }

修改了配置文件 必须执行重新加载配置文件命令 nginx -s reload

修改hosts文件 增加映射

127.0.0.1   first1.zns.com

127.0.0.1   first2.zns.com

浏览器访问

http://localhost:9000/

http://first1.zns.com/

http://first2.zns.com/

猜你喜欢

转载自www.cnblogs.com/zengnansheng/p/10389270.html
今日推荐