1. 程式人生 > >nginx代理跨域(mac)

nginx代理跨域(mac)

首先找到nginx.conf檔案,修改並新增如下配置

html 檔案

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<script src="./nginx轉發代理跨域.js"></script>
<body>
    <div>wew</div>
</body>
</html>
nginx轉發代理跨域.js

const url = '/apis/api/test'
fetch(url)
    .then(res => {
        console.log(res)
    })

上述,在瀏覽器中訪問會出現跨域,所以我使用nginx進行反向代理。由本地8080埠訪問伺服器地址3999埠,會出現跨域,所以我對該介面進行了轉發