前端跨域nginx配置反向代理
2020-05-16 本文已影响0人
大梦无痕
请求地址 http://test.tianguiedu.com/AjaxControls/WeiXinWeb/UserInfo.ashx
1.下载nginx 打开conf目录下的nginx.conf 配置如下
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888; # 任意
server_name localhost;
location / {
root html;
index index.html index.htm;
}
# 新加的
location /AjaxControls {
proxy_pass http://test.tianguiedu.com; # 后端接口 IP:port
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3.运行nginx cmd 进入nginx目录 运行 nginx.exe
4.ajax请求
$.ajax({
type:"get",
url:"/AjaxControls/WeiXinWeb/UserInfo.ashx",
success:function(res){
console.log(res)
}
})

5 配置HBuilder
image.png
image.png
image.png
当前确定完成配置 打开目录
image.png
image.png
image.png
image.png
关闭cmd 直接运行成功