linux配置nuxt项目

安装node: https://blog.csdn.net/jiangyu1013/article/details/80980765

安装pm2:npm install pm2 -g

 npm install报错,解决:npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass

部署nuxt项目到服务器

1.本地项目执行命令
npm run build
2.服务器新建一个文件夹备份上次的文件

3.将文件:static .nuxt nuxt.config.js package.js文件放入linux中,路径:/var/www/ssr-website/
4.命令窗口进入项目路径,执行命令 pm2 ls查看pm2管理的项目,
其中npm是对应的 sourcingbuy未登录的首页项目(项目名称改为website id是8)
5.关闭npm 命令
pm2 stop 0
//0是npm对应的id
5.1 如果有新引入的模块,需要npm install
6.启动项目
npm run start
7.开启进程守护
pm2 start npm --name "website" -- run start

8.删除旧的进程:根据id
pm2 delete id //id换成对应的数字

9.移动文件(或文件夹)到另一个文件夹
mv test.js sitemap.xml -t ./20211116
从文件夹移出文件到上一级文件
mv sitemap.xml -t ../
10删除文件
rm -rf /file

 

11.配置sitemap.xml

nuxt.config.js.js文件

sitemap: {
    path: '/sitemap.xml', // sitemap path,不用改
    hostname: 'https://www.sourcinbox.com',
    gzip: true,
    cacheTime: 1000 * 60 * 60 * 24,
    generate: false,
    exclude: ['/404', '/401'],
    defaults: {
      changefreq: 'always',
      lastmod: new Date()
    },
    routes: async () => {

      // 从后台获取数据,拼接url生成更多的xml数据
      // const getUrl = 'https://******'
      // const { data } = await axios.get(getUrl)
      const routes = [
        {
          url: "/",  //  这里的路径相对 hostname
          changefreq: "daily",
          lastmod: new Date(),
          priority: 1
        },
        {
          url: "/blog",
          changefreq: "daily",
          lastmod: new Date(),
          priority: 0.9
        },
        {
          url: "/partner",
          changefreq: "daily",
          lastmod: new Date(),
          priority: 0.9
        },
        {
          url: "/contact-us",
          changefreq: "daily",
          lastmod: new Date(),
          priority: 0.9
        },
        {
          url: "/blog/woocommerce-integration-with-sourcinbox",

changefreq: "daily",
          lastmod: new Date(),
          priority: 0.9

        },
]
    

      return routes
    }

  },

  运行项目命令:npm run generate

 

 将项目dist目录下sitemmap.xml放到服务器

 

 

 

 配置nginx

 

 如果更改sitemap.xml文件,需要重启nginx

 

posted @ 2021-08-04 15:11  枫若  阅读(284)  评论(0编辑  收藏  举报