Here we will use Nginx to serve static resources and reverse proxy dynamic requests to the Node server. We will also use Monit to monitor the Node server and restart it automatically in case it crash. This is also the deployment I did at fortune.crash4.us. [Nginx: Static Resources] livefortunes use express.static to server static resources, but for better performance we will use nginx to do the job that it’s designed and built to do. Config nginx to server all the static resources which located under /public : [cc lang=”bash”] server { listen 80; server_name fortune.crash4.us; root /path/to/livefortunes/public; index index.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } [/cc] [Nginx: Reverse Proxy] Our node server started separately and listened at another port (in this case, 8000), config nginx to reverse proxy all the dynamic requests to our backend node servers. [cc lang=”bash”] upstream node_server { server 127.0.0.1:8000; } server { … … try_files $uri/index.html $uri.html $uri @node_server; location @node_server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://node_server; } … … } [/cc] [sysvinit: Init Script] For the benefit of Monit, we will install a sysvinit script: [cc lang=”bash”] $ cd livefortunes $ cp script/livefortunes /etc/init.d/ $ chmod +x /etc/init.d/livefortunes [/cc] Then start and stop our livefortunes node server is as simple as: [cc lang=”bash”] $ /etc/init.d/livefortunes start $ /etc/init.d/livefortunes stop [/cc] [Monit: Auto Restart] Node server seems pretty enjoy crashing, from my experience, it crashes at least 2 times a day. Considering the site heavily relies on our node server, this is totally unacceptable. Thanks to Monit, we can restart Node server in a manageable and flexible way. Install Monit (debian, ubuntu): [cc lang=”bash”] $ aptitude install monit [/cc] Create a livefortunes monit config file in /etc/monit.d/livefortunes, restart the server if :8000/ doesn’t response in 10 seconds. [cc lang=”bash”] #!monit set logfile /var/log/monit.log check host livefortunes with address 127.0.0.1 start program = “/etc/init.d/livefortunes start” stop program = “/etc/init.d/livefortunes stop” if failed port 8000 protocol HTTP request / with timeout 10 seconds then restart [/cc] Include additional configuration files in /etc/monit/monitrc: [cc lang=”bash”] include /etc/monit.d/* [/cc] Setup Monit to start automatically and check intervals to 60 seconds in /etc/default/monit : [cc lang=”bash”] startup=1 CHECK_INTERVALS=60 [/cc] [Conclusion] Node server seems take more memory than my expectation, in my case, it takes more memory than nginx and mysql… LiveFortunes is still under development, for the latest code, please check out its github repository.
Live Fortune (Node.js) that do not crash
Do you enjoy reading interesting or funny sentences like below?
A nuclear war can ruin your whole day.
He who knows, does not speak. He who speaks, does not know. – Lao Tsu
If you do, check out: http://fortune.crash4.us/ ((Trust me, it won’t crash…)) For the record, this is a project built with Node.js, Express and Faye. One fortune will be pushed from server to each client every 2 mins thanks to the html5 WebSocket. Client can trigger a server push/broadcast as well ((open multiple browser windows or tabs to test)). All the source code is available at github. Next step is to convert this project to CoffeeScript.
Vim-Task overhauled with native vim script support
Thanks to anfernee, vim-task now supports vim native script, which means +ruby compile option is not required any more in your vim instance. This is great because the default vim package some Linux distributions (debian, ubuntu etc) distribute do NOT build with +ruby feature by default, which makes very frustrated experiences for these users. This commit simplifies the process and will eventually provide benefit in the long run. If you’re a user of vim-task and not so into ruby, upgrade is highly recommended.
Update 58: 其实我不喜欢皱眉
1. 周末理发,顺便想换换心情,洗头的mm貌似发现了什么,委屈的问我为啥老是皱着眉头,一时语塞,半响折腾出一句,“没有啦,估计我天生这表情……”,mm将信将疑地告诉我老是皱眉怎么怎么不好,怎么怎么不利于健康,我很defensive的一一小心附和着,防范着接下来随时可能出现的推销行为,后来不知道是我defend的好还是mm根本没这心,一切的谈话最后都只限于闲谈的范畴,mm也许真的只是在没话找话吧,事实证明所有的阴暗面全部来自于我这个阴谋论深度患者,只是我没有说出来而已;最后为了表示歉意,我假装随意的道出了我本来一直在avoid而mm也许早就猜到的事实:“其实我不喜欢皱眉的啦,只是最近祸不单行,心情不好,不好意思了”; 2. 当然,不喜欢皱眉只是个心理状态,也许我真的天生皱着眉也说不定 ((我觉得很cool啊,呵呵…)),这则不以我的意志为转移了; 3. 最近不知道为啥,开始喜欢刷新浪微博(很多事情真的很难解释),如果各位碰巧也用新浪微博的话,可以加我,当然就如各种国外流行serives的clone一样,sina的微博还是更偏重于娱乐,这不是judgement,只是我的opinion而已; 4. 在sina微博关联了blog,顺便测试下,不在话下; 5. btw,时间过的好快,一晃就好几年,再晃一下又是好几年,上上周看到一篇文章说人生只有大概900个月,震撼之于便只剩唏嘘,置此与大家共勉。
What's your color?
摘录一段最新一集 ((第四季第22集)) the big bang theory ((最近开始并且现在已经完全catch up,之前基本上属于两天一季的速度,汗…)) 里面的某段对话: Raj: I need a hug. Sheldon: Sorry, I have company. Raj: Come on, Sheldon, open the door. Sheldon: I don’t want to hug you. Raj: I don’t want to hug you either. I was just feeling blue. Sheldon: Blue, as in depressed. Raj: Well, not so much depressed as lonely. Sheldon: I don’t know what color lonely is. Raj: What? Sheldon: Red is angry; yellow is frightened; green is jealous; and blue is depressed. Perhaps we can assign a color to lonely. Raj: Nothing rhymes with orange. It’s probably lonely. Sheldon: All right. Come in. You look positively orange with loneliness. No, I don’t see that catching on at all. 也许字里行间看不出什么可以令人发笑的理由,确实,这也是为啥如果没有演员传神的表演你永远也不会 understand 为啥短短的几句对白背后会传来有至少5+次笑声的原因。 当然很多时候也许背后的笑声只是为了笑声而笑声,人都有从众心理,you know,即便那会并没有那么如此这般的真的能够让人忍俊不禁。 不过说起让人放松,愉悦心情,我是没有任何异议的,anyway, big fan. 我也不知道我上面是不是make了我的point,不过这显然也不是我这里想make的point…… 就我取的这个标题的意图而言(suppose我现在还记得正确),这个topic目前以及可预见的未来的方向已经算是完全out of control了…… 如果真的有time machine,我希望回到8分钟前,然后用下面的文字替换掉上面那堆不知所云的家伙: I really like the color metaphor here as I’m feeling some of the colors here as well recently, although not so much as the way here is. And… what’s your color recently?
Hey Jude
media downloaded from google.cn music Hey Jude – 孙燕姿 Hey Jude, don’t make it bad. Take a sad song and make it better. Remember to let her into your heart, Then you can start to make it better. Hey Jude, don’t be afraid. You were made to go out and get her. The minute you let her under your skin, Then you begin to make it better. And anytime you feel the pain, hey Jude, refrain, Don’t carry the world upon your shoulders. For well you know that it’s a fool who plays it cool By making his world a little colder. Hey Jude, don’t let me down. You have found her, now go and get her. Remember to let her into your heart, Then you can start to make it better. So let it out and let it in, hey Jude, begin, You’re waiting for someone to perform with. And don’t you know that it’s just you, hey Jude, you’ll do, The movement you need is on your shoulder. Hey Jude, don’t make it bad. Take a sad song and make it better. Remember to let her under your skin, Then you’ll begin to make it Better better better better better better, oh. Na na na na na na, na na na, hey Jude……
Update 57: Keep Silence
again, this update is intentionally left blank. ((no reason, no clue, no comment.))
Grid Archives 1.0.1 & 1.0.2
2 minor issues found after 1.0.0 released. If you’ve already upgraded to 1.0.0, upgrade to 1.0.2 is highly recommended. [ChangeLog]
- fixed a month date format display issue
- made the plugin compatible with wordpress 3.1
Please visit this archives page to see a live demo.
Grid Archives 1.0.0
While post date format customization feature was added in 0.7.0, it now feels inconsistent and very annoying if month date format can not be customized. This release covered this issue. Although 1.0.0 sounds like a major release, it actually adds only one feature as mentioned above :) If you have other feature requests, please feel free to leave comments. [ChangeLog]
- added an option to customize the date display format for months
As always, please visit this archives page to see a live demo. [Screenshots]