Nginx代理后端接口配置:
nginx 配置文件位置:nginx-1.18.0 \ conf \ nginx.conf
location /api {
proxy_pass http://www.xxx.com; #代理的后端接口
}
重启之后Ajax请求如下:
let req = {
number: 19119246190,
code: 23131
}
$.ajax({
url: "/api/login",
type: "post",
data: JSON.stringify(req),
headers: { "Content-Type": "application/json;charset=utf8" },
dateType: "json",
success: function (data) {
alert('登录成功')
},
error: function (e) {
console.log('登录失败', e)
}
});
修改nginx端口:
server {
listen 1234; #端口
server_name localhost;