一、下载 nginx https://www.nginx.cn/nginx-download
二、配置nginx.conf
#配置当前html的根目录以及当前界面的地址
server {
listen 8888;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ^~ /api {
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_buffering off;
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://192.168.1.100:8000; #转发到的地址
}
}
三、启动nginx
四、通过浏览器打开当前的程序,服务器地址加上当前的端口号:127.0.0.1:8888
五、当前的前端程序放的位置为 nginx-1.16.1/html 文件夹下
ajax,代码如下
$.ajax({
type: "post",
url: '/api/upload',
data: formData,
processData: false, // 告诉jQuery不要去处理发送的数据
contentType: false, // 告诉jQuery不要去设置Content-Type请求头
mimeType: "multipart/form-data",
xhrFields: {withCredentials: true},
contentType:false,
async: true, //默认是true:异步,false:同步。
success: function (msg) {
info.innerHTML = msg;
}});