美文网首页
前端跨域nginx配置反向代理

前端跨域nginx配置反向代理

作者: 大梦无痕 | 来源:发表于2020-05-16 11:54 被阅读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)
        }
    })
image.png

5 配置HBuilder


image.png
image.png
image.png

当前确定完成配置 打开目录


image.png
image.png
image.png
image.png

关闭cmd 直接运行成功

相关文章

网友评论

      本文标题:前端跨域nginx配置反向代理

      本文链接:https://www.haomeiwen.com/subject/qvplohtx.html