Project Summary blog site deployment issues

Recently the use of koa2 + mysql + nodejs + weback + vue + redis technology to build a blog site, but since the problems encountered, and now some eleven summary:

Questions 1. Use ecosystem.json profile deployment project,  " POST-Deploy " : " npm install && PM2 startOrRestart ecosystem.json --env Production's " , // publish a project to execute commands on the server 

Found in the configuration file or tutorials given by the network, can not access the website, the website reported nginx proxy issues, or simply 502  Bad  Gateway ;

 

Print pm2 log:

 

 

 Discovery service seemingly been killed and then evoke, and then killed. . . . .

Question 2. Then modify the configuration file, suspect the problem is to execute the command:

" POST-Deploy " : " npm npm install && && RUN prd PM2 startOrRestart ecosystem.json --env Production's " , // project issue commands to be executed on the server

Note that more than npm run prd, package.json corresponding commands in the file:

"prd": "cross-env NODE_ENV=production pm2 start bin/www --watch",

That allows the command to start the service, and then be able to access the page, but there will be a few questions:

  Problem: pm2 ls on the server will find more than a www processes on the original myblog process:

Similar shown above, of course, this is the correct view after the fact, there will be more than one line name for the www process, in fact, this process is executed  npm run prd-coming process.

Similar npm run prd executed on the server side www / website / myblog / current folder will play the same service, and then the process is www;

Well, even if we use npm run prd evokes the services, but there are still the following questions:

  Question 1: js, css and other static resources Web site references can not be cached;

  Question 2: deploy code for each execution command   PM2 Deploy ecosystem.json Production's  , will prompt the process server is running npm run prd [that is], every time the server shuts down the process and then execute the command, or with the -f command too many, has led the process.

  Question 3: The most deadly is the site after running for a long time, can only access static css, js and other resources, koa Scaffolding of api interface to all can not visit! ! ! ! !

------------

So the question, where is it?

Toss for a long time, various modifications of pm2 profile attempts, as well as nginx configuration files, or even reformatting the disk, re-build environment, will not work. . . . .

Until after a server can not access the interface api, I print pm2日志看了一下:

 

 

 Nani? ? ? It reported an error: loveNum undefined, then look at the following log:

 

 

 Because too many errors, cause the server to hang. . . . Bye. . . . . .

Finally I realized that the original logic itself is a problem, can not get the code to a value loveNum, the beginning can also run, but after a long time, a growing number of service errors stuck, so often run around performance for a long time, Interface hung up.

Well, until reason, the investigation business logic code, modify loveNum the bug, and then ecosystem.json configuration file, delete npm run prd; and modifying the "script": "./bin/www",// start entry script, ultimately ecosystem.json configuration file as follows:

{
   "Apps" : [{
     "name": "MyBlog", // name of the application's deployment of 
    "Script": "./bin/www", // entry script-initiated 
    "Watch": to true , // whether listening file changes 
    "env" : {
       "COMMON_VARIABLE": "to true" // incoming startup variables 
    },
     // Environment starting with the when the variables Injected Production's --env 
    // http://pm2.keymetrics.io/docs / Usage / file application-Declaration / #-Switching-to-Different Environments 
    "env_production" : {
       "NODE_ENV": "Production"// production environment variable 
    } 
  }], 
  //Part Deployment 
  // Here you DESCRIBE the each Environment 
  "Deploy": { // deployment task 
    "Production's" : {
       "the User": "Zyl", // on the server used to publish user names 
      // Multi Host IS Possible, the Just IPs passing by / hostname AS AN Array 
      "host": [ "39.106.194.136"], // host IP 
    "port": "22 is", // port number 
// Branch 
      "REF": "Origin / master", / / specify the main branch master 
      // Git Repository to clone 
      "repo": "[email protected]: zhenyulei / KOA-blog.git",// Warehouse Address 
      // Path of the Application ON at The target Servers
      "path" : "/home/zyl/www/website/myblog", //把项目部署到服务器的那个目录下
      // Can be used to give options in the format used in the configura-
      // tion file.  This is useful for specifying options for which there
      // is no separate command-line flag, see 'man ssh'
      // can be either a single string or an array of strings
      "ssh_options": "StrictHostKeyChecking=no", //把ssh的key校验取消掉
      // To prepare the host by installing required software (eg: git)
      // even before the setup process starts
      // can be multiple commands separated by the character ";"
      // or path to a script on your local machine
      "pre-setup" : "",
      // Commands / path to a script on the host machine
      // This will be executed on the host after cloning the repository
      // eg: placing configurations in the shared dir etc
      "post-setup": "ls -la",
      // Commands to execute locally (on the same machine you deploy things)
      // Can be multiple commands separated by the character ";"
      "pre-deploy-local" : "echo 'This is a local executed command'",
      // Commands to be executed on the server after the repo has been cloned
      "POST-Deploy": "npm install && PM2 startOrRestart ecosystem.json --env Production's", // publish a project to execute commands on the server 
// Environment Injected in the Variables that the MUST BE ON the this env All Applications 
      "env": { "NODE_ENV": "Production's" }}} 
}

Perform again:

pm2 deploy ecosystem.json production setup 

pm2 deploy ecosystem.json production

binggo! ! The site was finally able to visit!

Not only solved the problem of sites to visit, and the site has also been static resource cache, in addition to re-look at the ls pm2

 

 

Look at their logs, we have normal:

 

 

 Finally done.

---

Other issues, set up in the server's cache and found

 

Wherein conf.d nginx is disposed is routed to a folder, and is http nginx.conf profile settings of nginx.

So set caching and compression should be placed nginx.conf file settings.

In addition, with favicon.icon: Use webpack packed single-page document how the project set favicon.icon

The easiest way is placed directly at the end koa public folder, be sure to pay attention to the name of the standard: favicon.icon

 

upstream myblog {
    server 127.0.0.1:8000;
}
server {
    listen 80;
    server_name www.blog.xiaozhumaopao.com;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Nginx-Proxy true;
        proxy_set_header X-Forwarded-Host $server_name;

        proxy_pass http://myblog;
        proxy_redirect off;
    }

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt){
      root /home/zyl/www/website/myblog/current/public;
    }

}

 

Guess you like

Origin www.cnblogs.com/xiaozhumaopao/p/11785537.html
Recommended