react项目部署到linux服务器

react部署笔记

1.1打包项目

#安装yarn
npm install -g yarn
#打包项目
yarn build

1.2 将打包好的build 推到服务器

# cd到前端web目录
cd /usr/local/web/lwh
#build文件夹放到这路径下

1.3配置Nginx代理配置

修改nginx.conf文件

#文件nginx.conf
# nginx的配置文件位置
cd /usr/local/nginx/conf
# 编辑nginx文件
vim nginx.conf
#添加如下内容,xxx为你的项目名字
include confile/xxx.conf;

创建xxx.conf 对应项目nginx配置文件

cd confile
#创建xxx项目nginx配置文件
mkdir xxx.conf
# 编辑xx.conf配置文件
vim xxx.conf

xxx.conf文件内容

server{
    listen 80;
    server_name lwhtimepill.leiweihao.ltd;
    rewrite ^(.*)$ https://${server_name}$1 permanent;
}
server{
    listen 443;
    server_name lwhtimepill.leiweihao.ltd;
    ssl     on;
    ssl_certificate /usr/local/nginx/conf/cert/lwhtimepill.leiweihao.ltd_nginx/lwhtimepill.leiweihao.ltd_bundle.pem;
    ssl_certificate_key /usr/local/nginx/conf/cert/lwhtimepill.leiweihao.ltd_nginx/lwhtimepill.leiweihao.ltd.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    location / {
        proxy_pass http://127.0.0.1:21010; 
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host                    $http_host;
    }
}
server{
    listen 21010; 
    location /{
        root /usr/local/web/lwh/timepill/build;
        try_files $uri /index.html;
    }
    error_page  404              /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
    location ~/api/(.*){
        proxy_pass http://localhost:21011;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
        proxy_set_header           Host $host;
        proxy_set_header           X-Real-IP $remote_addr;
        proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
        rewrite  ^/api/(.*)  /$1 break;
    }
}

1.4域名申请ssl证书,下载到服务器

>>> cd /usr/local/nginx/conf/cert/lwhtimepill.leiweihao.ltd_nginx
>>> ls
lwhtimepill.leiweihao.ltd_bundle.crt  lwhtimepill.leiweihao.ltd_bundle.pem  lwhtimepill.leiweihao.ltd.csr  lwhtimepill.leiweihao.ltd.key

1.5重启nginx

#重启nginx
nginx -s reload

1.6配置完成,网站正常访问

https://lwhtimepill.leiweihao.ltd/home

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值