宝塔安装next.js框架 / 本地同步到宝塔

📅 2026/8/20 22:33:51
宝塔安装next.js框架 / 本地同步到宝塔
安装Nginx 1.30.3 和 Node.js版本管理器 2.7 注意版本进入终端 cd 你网站根目录执行npx create-next-applatest . 一路yes 就ok了简单吧接下来就可以基于next.js部署自己的网站了。----------------本地同步到宝塔cd /www/wwwroot cd你网站的根目录git clone gitgithub.com:xxxx/odi-xxxx.cn.git odi git clone 到你根目录的odi文件夹如果服务器没有配 GitHub SSH key用 HTTPS 方式私有仓库会提示输用户名tokengit clone https://github.com/ijoanne888/odi-xxxx.cn.git odicd odi# 不带 odi → 自动用仓库名作为目录名git clone gitgithub.com:xxxx/odi-xxxx.cn.git# 结果/www/wwwroot/odi-xxxx.cn/# 带 odi → 指定目录名叫 odigit clone gitgithub.com:xxxx/odi-xxxx.cn.git odi# 结果/www/wwwroot/odi/根据你想目录使用的node 安装对应的版本 node -vnpm cinpm run build 把你的项目从“开发状态”打包成“可以部署上线的生产版本”。cd /www/wwwroot/xxx.cnnpm install -g pm2pm2 start npm --name odi -- startpm2 savepm2 startup然后确认状态pm2 listpm2 logs odi --lines 10 (看到Ready on http://localhost:3000就说明服务跑起来了接着去宝塔配 Nginx 反向代理就行。------------------现在只剩最后一步——宝塔 Nginx 配置反向代理宝塔面板 → 网站 → 找到 xxx.cn→ 设置 → 配置文件在server块里加或替换已有的location /location / { proxy_pass http://127.0.0.1:3002; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_bypass $http_upgrade; }同时将以下内容注释#location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #{ # expires 30d; # error_log /dev/null; # access_log /dev/null; #} #location ~ .*\.(js|css)?$ #{ # expires 12h; # error_log /dev/null; # access_log /dev/null; #}改完后先验证配置nginx -t没问题就保存然后访问即可