mac系统下nginx 配置web服务器 配置react BrowserRouter

1、 安装nginx
2、nginx conf 配置端口和网页文件夹位置
3、启动nginx
4、把webpack代理修改为nginx代理

mac 启动和配置nginx
vim /usr/local/etc/nginx/nginx.conf 按i 进入编辑模式
esc
:wq 保存
brew services start nginx 启动nginx
brew services restart nginx 重启nginx

使用browserRouter 需要配置nginx

location / {
   try_files $uri /index.html;
}

子路径下则是

location / {
   try_files $uri /子路径/index.html;
}

使用nginx 配置跨域出现CSOR 同源策略

配置跨域为

locatiion /api{
  proxy_pass http://xxx.xxx.com 
}

结果出现跨域错误,百思不得其解。。。。 WTF,我反向代理还说我
Access to fetch at 'https://xxxxxx.xxx.xx' (redirected from 'http://localhost:8080/api') from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

咋回事呢???

结果发现 proxy_pass http://xxx.xxx.com这里少了个s,然后在浏览器访问http://xxx.xxx.com会自动跳转到https://xxx.xxx.com,这就给排查问题增加了一层难度。

你可能感兴趣的:(mac系统下nginx 配置web服务器 配置react BrowserRouter)