type
status
date
slug
summary
tags
category
icon
password
react history mode 在 nginx 的部署
react-router官方推荐,需要服务器支持,因为是 SPA 项目,url 切换时需要服务器始终返回
index.html。当前项目打包后的文件在
/var/www/bing-collect 文件夹下。部署在根目录
设置 homepage
设置
package.json 的 homepage 为 . 。运行
yarn build 命令后构建的 index.html 关于静态资源的引用是这样的:这里会以相对路径的形式引用静态资源。
nginx 配置
设置访问页面时始终返回
index.html 。部署在子目录
如果需要部署在子目录,例如
http://localhost/bing-collect 类似的路径。设置 basename
需要设置 basename 为
/bing-collect 。设置 homepage
设置
package.json 的 homepage 为 /bing-collect 。运行
yarn build 命令后构建的 index.html 关于静态资源的引用是这样的:这里会以绝对路径的形式引用静态资源。
nginx 配置
访问
bing-collect 子目录时,重定向到 index.html 。nginx 的一些知识点
常用命令
开机自启启动关闭在启动
修改 nginx.conf 后
nginx 配置
- 作者:张小手
- 链接:https://zxs-1024.cn/article/react-and-nginx
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。