天天看点

nginx 配置 react项目,首页不是index.html

nginx 配置 react项目,首页不是index.html

在 react 项目开发时, 一般有 hashHistory 和 browserHistory 的方式, 在项目打包出来之后,需要部署到服务器上面,碍于实际需求,我们的首页很有可能不是index.html , 于是在网上找了不少资料, 才配置成功这么一套部署方式, 作为参考

server {
  listen          8012; # 监听端口号
  server_name     localhost;
  location / {
      # 配置访问本服务器的根目录
      root /Users/a063/Project/code/new-ppy-cloud/build;
  }
  location /test/module/ {
      # 配置访问路由中带有 /test/module/ 的路径指向
      # 访问本服务器时, 只要路径带有 /test/module/ , 最终返回的就是 test.html 
      # 所以要注意接口请求不要带有 /test/module/
      try_files $uri /test.html;
  }
  location /api {
      # 接口转发配置, 以 /api 开头的请求, 都会转发到下面的域名
      proxy_pass   https://test.com;
  }
}
           

继续阅读