From 9f3dab12bc2e2c8baa9e7403d99faac2e3113606 Mon Sep 17 00:00:00 2001 From: Tjatse Date: Tue, 3 Mar 2015 15:25:35 +0800 Subject: [PATCH] compatible with vhost --- README.md | 42 +++++++++++++++++++++++++++++++++ lib/pm.js | 1 - test/fixtures/startup.json | 48 ++++++++++++++++++++++++++++++++++++++ web/public/js/auth.html.js | 2 +- web/views/auth.html | 18 +++++++------- web/views/index.html | 32 ++++++++++++------------- 6 files changed, 116 insertions(+), 27 deletions(-) create mode 100644 test/fixtures/startup.json diff --git a/README.md b/README.md index b7ed302..01d6946 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ An elegant web interface for Unitech/PM2. - [Configs](#cli_confs) - [Authorization](#auth) - [UI/UX](#ui) +- [Serving apps locally with nginx and custom domain](#serv) # Features @@ -212,6 +213,47 @@ Tail Logs ![image](screenshots/logs.jpg) + +# Serving apps locally with nginx and custom domain + +```ini +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + +upstream pm2-gui { + server 127.0.0.1:8000; +} + +server { + listen 80; + server_name pm2-gui.dev; + + #useless but can not get rid of. + root /path/to/pm2-gui/web/public; + + try_files $uri/index.html $uri.html $uri @app; + + # paths + location @app { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + + proxy_pass http://pm2-gui; + } + + # socket.io + location /socket.io { + proxy_pass http://pm2-gui; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + } +} +``` + ## Test ```bash $ npm test diff --git a/lib/pm.js b/lib/pm.js index 6eb89c4..363dbed 100644 --- a/lib/pm.js +++ b/lib/pm.js @@ -36,7 +36,6 @@ pm.sub = function(sockPath, cb){ // Process events. sub.on('process:*', function(e, d){ - console.log(d); if (d && !!~allowedEvents.indexOf(d.event)) { cb(d); } diff --git a/test/fixtures/startup.json b/test/fixtures/startup.json new file mode 100644 index 0000000..81ec07c --- /dev/null +++ b/test/fixtures/startup.json @@ -0,0 +1,48 @@ +{ + "apps": [ + { + "name": "Colorful", + "script": "colorful.js", + "cwd": "test/fixtures", + "args": [ + "--color" + ] + }, + { + "name": "Exit Immediately", + "script": "exit.js", + "cwd": "test/fixtures" + }, + { + "name": "Fibonacci", + "script": "fib-slow.js", + "cwd": "test/fixtures" + }, + { + "name": "Fibonacci", + "script": "fib-slow.js", + "cwd": "test/fixtures" + }, + { + "name": "Randomize", + "script": "rand.js", + "instances": 0, + "cwd": "test/fixtures" + }, + { + "name": "Throw Error", + "script": "throw.js", + "cwd": "test/fixtures" + }, + { + "name": "Tick", + "script": "tick.js", + "cwd": "test/fixtures" + }, + { + "name": "Tock", + "script": "tock.js", + "cwd": "test/fixtures" + } + ] +} \ No newline at end of file diff --git a/web/public/js/auth.html.js b/web/public/js/auth.html.js index 57a5ff5..0bfea96 100644 --- a/web/public/js/auth.html.js +++ b/web/public/js/auth.html.js @@ -31,7 +31,7 @@ function login(){ // Post data to server. lightUp(); $.ajax({ - url : '/auth_api?t=' + Math.random(), + url : 'auth_api?t=' + Math.random(), data : { pwd: val }, diff --git a/web/views/auth.html b/web/views/auth.html index afd7851..0950f9e 100644 --- a/web/views/auth.html +++ b/web/views/auth.html @@ -6,12 +6,12 @@ - - - - + + + + - + @@ -25,10 +25,10 @@ - - - - + + + + \ No newline at end of file diff --git a/web/views/index.html b/web/views/index.html index e700a05..d21a7b7 100644 --- a/web/views/index.html +++ b/web/views/index.html @@ -6,12 +6,12 @@ - - - - - - + + + + + + @@ -44,16 +44,16 @@
- - - - - - - - - - + + + + + + + + + +