nginx跨域配置


一、下載  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;
}});

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM