CRA项目部署

对于前端开发者来说,有时候也需要将开发环境下的代码部署到生产环境中去,这个时候就需要一点nginx的知识了。本文从头开始将一个崭新的CRA前端工程部署到生产环境去中。

1. 前端项目构建

bash 复制代码
cd C:/Users//Administrator//Documents
npx create-react-app demo --template=typescript
code ./demo
# 打包之前记得在package.json中增加、修改homepage为"."即:"homepage":".",
yarn build

2. 配置nginx.conf

打开nginx配置文件nginx.conf,在http模块下新增一个服务:

nginx 复制代码
server {
  listen 80;
  server_name your_domain.com;  # 將 your_domain.com 替換為你的域名或 IP
  
  location /reminder {
      alias C:/Users/Administrator/Documents/demo/build;
      index index.html;
      try_files $uri $uri/ /reminder/index.html;
  }
}

3. 启动nginx

在nginx.exe所在的目录下面打开cmd然后执行启动命令

cmd 复制代码
nginx.exe

4. 测试

在浏览器的地址栏中输入:http://nginx所在的机器的ip地址/reminder

如果能够展示出来打包之后的效果就成功了!

相关推荐
程序员大阳1 小时前
副队长ES6+教程(10)--迭代器 Iterator 与 for...of
javascript·es6·遍历·for of
夕水1 小时前
受不了满屏广告的诗词网站,以及很多打不开的诗词网站,我干脆自己租服务器用trae重构了一个(纯公益、无广告)
前端·javascript
程序员大阳1 小时前
副队长ES6+教程(15)--async和await
javascript·es6·async·promise·同步·异步·await
Brookty2 小时前
HTML基础知识:表格布局、表单数据提交、元素标识与资源相对路径
前端·html
徐小夕2 小时前
开源!我们用知识图谱重构了电子档案,AI 驱动全文智能关联
前端·vue.js·github
不一样的少年_2 小时前
用了这 Skill,前端兄弟都觉得好
前端·后端·ai编程
恋猫de小郭3 小时前
Flutter Native Interop 稳定了,Platform Channel 要退场了
android·前端·flutter
奶油话梅糖3 小时前
容器启停 2.5 毫秒:11 天 1,700 Star 的 Kiri,用一个 900 KB 的 PID 1 干掉了 runc 和 dockerd
前端·人工智能·rust
Csvn14 小时前
Nginx 静态站点与 location 匹配:优先级、alias、缓存头与 gzip
后端·nginx