线上部署

PM2部署

pm2.json

  1. //use pm2 start app
  2. //pm2 startOrGracefulReload pm2.json
  3. {
  4. "apps": [
  5. {
  6. "name": "node",
  7. "script": "index.js",
  8. "cwd": "/acs/data",
  9. "max_memory_restart": "300M",
  10. "instances" : 2,
  11. "exec_mode" : "cluster",
  12. "autorestart": true,
  13. "max_restarts": 10,
  14. "node_args": "",
  15. "args": [],
  16. "env": {
  17. "NODE_ENV": "production"
  18. }
  19. }
  20. ]
  21. }

pm2启动命令

  1. pm2 startOrGracefulReload pm2.json

Nginx反向代理

nginx.conf

  1. server {
  2. listen 80;
  3. server_name _;
  4. index index.html index.js;
  5. root /acs/data/static;
  6. set $node_port 3000;
  7. if ( !-f $request_filename ){
  8. rewrite (.*) /index.js;
  9. }
  10. location = /index.js {
  11. #proxy_http_version 1.1;
  12. proxy_set_header Connection "";
  13. proxy_set_header X-Real-IP $remote_addr;
  14. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  15. proxy_set_header Host $http_host;
  16. proxy_set_header X-NginX-Proxy true;
  17. proxy_set_header Upgrade $http_upgrade;
  18. proxy_set_header Connection "upgrade";
  19. proxy_pass http://127.0.0.1:$node_port$request_uri;
  20. proxy_redirect off;
  21. }
  22. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico|svg|cur|ttf|woff)$ {
  23. expires 30d;
  24. }
  25. location ~ .*\.(js|css)?$ {
  26. expires 7d;
  27. }
  28. #access_log /acs/logs/access_nginx.log combined;
  29. }

docker容器部署

参看Dockerfile