用 nginx 做到代理服务器 使用

项目 要求  在windows 上 安装 nginx 实现 代理连接sinaApi

一.下载 nginx-1.18.0.zip   安装nginx

二. 改nginx的config

配置文件目录  C:\nginx-1.18.0\conf

1. 将nginx的端口改为 另外的端口, 不然会和本地的 web冲突

2. 增加 sina 的代理

增加一个  location 节点

复制代码
location /sina/ {
    #proxy_pass http://sina_server/;  
    #proxy_pass http://192.168.0.103:80/;
    proxy_pass http://192.168.1.5:80/;
             
        proxy_redirect  off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
复制代码

目的:  

复制代码
this.$axios.post('/sina/api/sessions', params)
.then(function (response) {
        console.log(response);
        let { token, extn } = response.data;//解析JSON
        console.log(token);//token---- 
 
}.bind(this))
  .catch(function (error) {
        console.log(error);
});
复制代码

此时的 $axios.post('/sina/api/sessions', params)

相当于 把 /sina/  换成了  

变为  $axios.post('http://192.168.1.5:80/api/sessions', params)

实现了 代码服务器的目的。

三.启动 nginx

注意: 更改配置后, 必须在管理器中杀掉进程, 然后再重启, 不然配置无效

安装目录  C:\nginx-1.18.0 

四. 把html程序,放在

C:\nginx-1.18.0\html

 

 五.在浏览器中访问

http://localhost:8088/

 

posted @   海乐学习  阅读(80)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2017-06-26 easyui-linkbutton 设置和获取text文本
2013-06-26 CSC时无法找到C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib
2011-06-26 vs2008 C++ 没有找到MSVCR90D.dll 问题
点击右上角即可分享
微信分享提示