前言
在日常工作中,某些API需要域名才能访问,这个时候需要做一个代理。
一、首先需要先安装ngxin
1.安装ngxin
- 打开Nginx官网:http://nginx.org/ ,下载ngxin 解压安装、
2.配置,启动ngxin
- 打开nginx文件夹,找到conf/nginx/conf配置文件
- 修改location /{}
- 代码如下(示例):
location / {
root html;
index index.html index.htm;
proxy_pass http://xxx.xxx.xxx/;//本地项目运行地址
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
这里端口使用默认80端口, http://xxx.xxx.xxx/ 是你本地运行的服务地址
- 配置完双击nginx应用
- 浏览器输入 http:localhost:80, 看下是否能访问,能访问则 nginx已经启动成功,且配置没有问题
二、配置本地host
1.管理员权限运行cmd
- 终端运行 :cd c:\windows\system32\drivers\etc** //进入etc目录
- 终端运行: notepad hosts // 打开host文件
2.配置host
- 配置代码如下
127.0.0.1 www.haha.com
现在访问http://www.haha.com 这个域名便可解析到本地的 http://xxx.xxx.xxx/