1.Nginx使用命令:
1. 启动命令:start nginx;(在nginx.exe目录下)
2. 重启命令:nginx -s reload;
3. 快速关闭命令:nginx -s stop;
4. 友好的关闭:nginx -s quit.
修改完Nginx配置文件需要重启Nginx才会生效.
2.Nginx反向代理配置:
配置之前需要配置hosts文件:
hosts文件的作用是完成域名和指定IP地址的映射。
hosts文件路径一般如下:
hosts文件的配置如下:
3.Nginx本地代理配置:
#后台管理服务器(代理端口)
server{
listen 80; #代理监听端口
server_name manage.jt.com; #需要代理的url域名
location /{
#proxy_pass 表示代理的路径
proxy_pass http://localhost:8091; #需要代理的url请求
}
}
4.Nginx图片代理配置:
#配置图片服务器
server{
listen 80; #表示监听80端口
server_name image.jt.com; #表示需要代理的url域名
location /{
root E:/image; #表示代理到的本地磁盘目录
}
}
经过以上配置,当我们再访问manage.jt.com时,访问路径等同于localhost:8091
Nginx配置的含义:
1.location
location = / {
[ configuration A ]
}
location / {
[ configuration B ]
}
location /documents/ {
[ configuration C ]
}
- "=/“表示只拦截url+”/"请求;
- "/“表示拦截url+”/"开头的请求,如:http://xxx.xxx.xxx/index.html;
- "/documents/“表示拦截url+”/documents/…"的请求;