Windows下使用Nginx
链接
使用
- 配置环境变量
- 使用命令
常用命令
首先需要进入安装目录,然后进入CMD执行以下命令
D:\nginx>nginx -h # 查看nginx命令帮助信息
D:\nginx>nginx -v # 查看nginx版本
D:\nginx>nginx -t # 检测nginx配置文件是否正确
D:\nginx>start nginx # 启动nginx,不阻塞CMD
D:\nginx>nginx # 启动nginx,阻塞CMD
D:\nginx>nginx -s stop # 停止nginx,不保存信息
D:\nginx>nginx -s quit # 停止nginx,保存信息
D:\nginx>nginx -s reload # 重载nginx,配置信息修改时使用
D:\nginx>nginx -s reopen # 重启nginx
案例
使用nginx代理新的页面,且不影响原有的配置文件(nginx.conf)
- 在nginx.conf的http节点下,最后一行,添加这句:
include vhost/*.conf;
- 在nginx.conf同级目录下创建vhost目录,然后在vhost目录中创建test.conf文件
将以下内容加入test.conf文件中
server { listen 8080; # 监听另一端口,避免与nginx.conf中监听的端口冲突 server_name localhost; location / { root 新页面路径; index index.html index.htm; } }
- 使用
start nginx
命令启动nginx,并在浏览器中访问:http://localhost:8080/