linux部署nuxt.js项目
安装nodejs包
sudo wget https://nodejs.org/dist/v10.14.2/node-v10.14.2-linux-x64.tar.xz
sudo tar -xvJf node-v10.14.2-linux-x64.tar.xz
sudo mv
node-v10.14.2-linux-x64 /usr/
local/nodejs
sudo vim /etc/profile
# 添加环境变量
export PATH=${PATH}:/usr/local/nodejs/bin
#刷新权限
source /etc/profile
#测试
node -v
安装pm2
yarn add pm2 globalcurl -v https://tgz.pm2.io
修改nginx配置,代理
http { ...... ...... include /etc/nginx/conf.d/*.conf; }
conf.d/[项目名].config
......
......
upstream nodenuxt { server 127.0.0.1:8081; #nuxt项目 监听端口 keepalive 64; } server { listen 80; server_name merchmanage.jxd007.cn; #charset koi8-r; #access_log /var/log/nginx/host-[项目名].access.log main; location / { proxy_pass http://nodenuxt; } location /api{ add_header Access-Control-Allow-Origin *; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:8080; } ...... ...... }
将项目上传到服务器,修改package.config
"config": { "nuxt": { "host": "127.0.0.1", "port": "8081" } }
修改项目axios baseUrl
打包项目
yarn build
开启项目
pm2 start yarn --name [项目名] -- run build