Nodejs学习(六)---nginx反向代理

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;上的接口.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值