nginx介绍
- 高性能的web服务器,开源免费
- 一般用于做静态服务,负载均衡
- 反向代理
下载
http://nginx.org/en/download.html
解压到c盘下名称改成nginx
进入window的cmd窗口,进入到nginx目录,使用“start nginx.exe ”进行nginx的安装,
然后在浏览器中就可以访问
- start nginx.exe //启动nginx
- nginx -t // 检查配置文件格式是否正确
- nginx.exe -s stop //停止nginx
- nginx.exe -s reload //重新加载nginx
- nginx.exe -s quit //退出nginx
配置文件 nginx.conf
C:\nginx\conf
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
#root html;
#index index.html index.htm;
#}
location /api/ {// nodejs 接口访问地址
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
}
location / { //项目访问地址
proxy_pass http://localhost:5500;
}
proxy_pass
设置代理地址
proxy_set_header
设置头部信息
网站输入localhost:8080
—代理到localhost:5500
,当访问接口/api
的时候 请求的是 http://localhost:8000;
上的接口.