1、打包npm run build 生成dist文件夹

2、 将dist中的文件拷贝到nginx服务器的html文件夹中

3、 修改 nginx.conf配置文件,配置端口号为9000

4 、用管理员权限打开cmd,启动ginx :start  nginx

ubuntu下部署情况

  • 1、打包好你的react本地项目,dist中具有打包好的文件
  • 2、将dist里的文件夹拷贝/home/root/下创建的react-demo文件中
  • 3、进入/usr/local/nginx/conf/nginx.conf  打开文件vi nginx.conf
server {
        listen 9000;
        # server_name your.domain.com;
        root /home/root/react-demo;
        index index.html index.htm;
        location / {
                try_files $uri $uri/ /index.html;
        }
        location ^~ /assets/ {
                gzip_static on;
                expires max;
                add_header Cache-Control public;
        }
        error_page 500 502 503 504 /500.html;
        client_max_body_size 20M;
        keepalive_timeout 10;
}
  • 4、重启nginx, 进入/usr/local/nginx/sbin下,输入命令./nginx -t(检验nginx配置格式),或者/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  • 5、访问你的ip+端口号9000,就可以打开网站了
  • 6、更新代码时将/home/root/react-demo中的旧代码删掉,再将打包好的代码上传到/home/root/react-demo中

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐