---
title: "Nginx windows 入门"
author: "davidforit"
date: "2018-06-07T18:01:24Z"
tags: []
categories: ["开源软件"]
slug: "nginx-windows"
draft: false
lastmod: "2018-06-08T09:08:27Z"
id: 2424533
url: "https://davidhhs.iteye.com/blog/2424533"
---

这里介绍windows下nginx的入门例子，个人练手用，这里测试使用的 nginx1.8.1版本，下载后解压到本地即可启动服务。配置文件路径：nginx-1.8.1\\conf\\nginx.conf。修改好配置文件执行dos命令启动服务。命令如下：

 

```
// 打开命令行工具，到nginx.exe同级目录，用命令启动/关闭/重启nginx 
 
start nginx  // 启动nginx
nginx -s reload  // 修改配置后重新加载生效
nginx -s reopen  // 重新打开日志文件
nginx -t -c /path/to/nginx.conf  //测试nginx配置文件是否正确

// 关闭nginx：
nginx -s stop  // 快速停止nginx
nginx -s quit  // 完整有序的停止nginx
```

 

 

[nginx下载](http://nginx.org/)

 

**配置文件设置如下：**

```
#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
	
	#html文件
    server {
        listen       80;
        server_name  localhost;

        location / {
			# html文件本地路径（修改为文件存放路径）
            root   D:/tools/nginx/source/html;
            index  index.html index.htm;
			charset utf-8;
        }

        location /file/ {
			# 静态资源文件本地路径，和html文件相同服务设置方式。（修改为文件存放路径）
            alias   D:/tools/nginx/source/static/;
        }
	
    }

	#静态文件
	server {
        listen       8001;
        server_name  localhost;
		
        location /file/ {
			# 静态资源文件本地路径，和html文件不同服务设置方式。（修改为文件存放路径）
            alias   D:/tools/nginx/source/static/;
        }
	}
}
```

 

 

 

**html 代码：**

 

```
<!doctype html>
<html lang="zh-cn">
	<head>
		<meta charset="utf-8">
		<meta name="description" content="Common form elements and layouts" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Nginx Test</title>
	</head>
<body>
<div style="font-size:20px;font-weight:bold;color:red;padding:20px;">Nginx 测试页面</div>
<table>
	<tr>
		<td><img src="file/xy.jpg"/></td>
		<td><img src="http://localhost:8001/file/xy.jpg"/></td>
	</tr>
	<tr>
		<td align="center">静态资源文件和html文件相同服务地址设置方式</td>
		<td align="center">静态资源文件和html文件不同服务地址设置方式</td>
	</tr>
</table>

</body>
</html>
```

 

 

访问方式： 

http://localhost/