部署React项目

通过上节的方法打包出来的react项目是无法直接运行的,我们需要借助一些web容器。

由于打包的文件是静态文件,所以不建议使用类似Tomcat的容器。

我们这里使用nginx。

nginx的配置请参考其文档。

我们将项目放到指定的目录下,比如 %nginx_home%/html/react.

在开发环境中配置的 proxy 也需要在nginx中配置:

location /api/ {
  proxy_pass   http://192.168.0.10:8080/api/;
}

如果你的项目是多入口,或者某些路由需要指到 index.html ,那么需要配置 try_files:

location /assets {
  root  html/react;
  index  index.html index.htm;
  try_files $uri $uri/ /assets/index.html;
}

results matching ""

    No results matching ""