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

Nginx作为静态内容服务器(Windows环境)

2014-10-27 15:38 453 查看
1、简单安装

  1)下载

http://nginx.org/en/download.html


  2)解压后的路径

E:\Study\nginx\nginx-1.7.6


  3)执行nginx.exe,访问http://localhost ,出现Welcome to nginx!欢迎内容,安装成功。

  4)在安装路径的logs目录下,会自动生成一个nginx.pid文件,文件内容就是nginx的主进程pid。

2、简单使用命令

nginx -s stop    快速停止
nginx -s quit    安全退出(会处理完正在进行的请求)
nginx -s reload    修改了nginx的配置文件后执行该命令生效
nginx -s reopen    重打开日志文件


3、静态内容服务器

  访问html文件时,让nginx映射到/data/html路径下;访问图片文件时,让nginx映射到/data/image路径下。

  1)创建data目录,然后在data目录下分别插件html目录和image目录。

  2)在html目录中放入index.html、hello.html文件

  3)在image目录中放入1.jpg、2.jpg两张图片

  4)配置nginx.conf

    在http节点内的server节点中进行配置。

location / {
#指定根目录
root   E:/Study/nginx/nginx-1.7.6/data/html;
#指定首页
index  index.html;
}

location /image/ {
#指定根目录
root   E:/Study/nginx/nginx-1.7.6/data;
}


  5)请求 http://localhost/image/1.jpg 时,Nginx自动响应 http://localhost/data/image/1.jpg
    请求 http://localhost/hello.html 时,Nginx自动响应 http://localhost/data/html/hello.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: