下载 nginx
地址: http://nginx.org/en/download.htm https://nginx.org/en/download.htm
下载后如下
启动 nginx
直接双击 nginx.exe, 双击后一个黑色的弹窗一闪而过
打开 cmd 命令窗口, 切换到 nginx 解压目录下, 输入命令 nginx.exe 或者 start nginx , 回车即可
检查 nginx 是否启动成功
直接在浏览器地址栏输入网址 http://localhost:80 http://localhost/ , 回车, 出现以下页面说明启动成功
也可以在 cmd 命令窗口输入命令 tasklist /fi "imagename eq nginx.exe" , 出现如下结果说明启动成功
nginx 的配置文件是 conf 目录下的 nginx.conf, 默认配置的 nginx 监听的端口为 80, 如果 80 端口被占用可以修改为未被占用的端口即可
检查 80 端口是否被占用的命令是: netstat -ano | findstr 0.0.0.0:80 或 netstat -ano | findstr "80"
当我们修改了 nginx 的配置文件 nginx.conf 时, 不需要关闭 nginx 后重新启动 nginx, 只需要执行命令 nginx -s reload 即可让改动生效
有的时候也会失效, 还是需要关闭 nginx 重启
nginx 配置静态资源
将静态资源 (如 jpg|PNG|CSS|JS 等) 放在如下配置的 f:/nginx-1.12.2/static 目录下, 然后在 nginx 配置文件中做如下配置(注意: 静态资源配置只能放在 location / 中), 浏览器中访问 http://localhost:80/1.PNG http://localhost/1.PNG 即可访问到 f:/nginx-1.12.2/static 目录下的 1.PNG 图片
来源: http://www.bubuko.com/infodetail-3716287.html