nginx结合node.js安装使用

来源:互联网 发布:人才结构优化措施 编辑:程序博客网 时间:2024/06/06 00:17

最近想给团队做个Web站点,本来想用Apache的,后来想到现在好像流行nginx,那就学习一下nginx吧。

nginx官网:http://nginx.org/  点击download下载windows版本,我下的是1.1.14版,压缩包只有1.08M,真是小啊。我把它解压到 D:\Developer\nginx-1.1.14下,双击nginx.exe,弹出一个黑屏就消失了。查看进程


启动两个进程。

浏览器输入 http://localhost/


OK可以使用

不过打开关闭太麻烦了,还要手动关进程,有没有像apache那样的托盘就好了

google一下,还真有,软件叫nginxtray 官网 http://nginxtray.codeplex.com/ 是codeplex的开源项目,我下的1.0版

我下载后解压到D:\Developer\NginxTray 1.0

双击执行 NginxTray.exe,托盘多个图标


提供打开、关闭和重启功能,不过使用前需要配置一下nginx的位置

点击settings


Nginx Directory 是nginx的解压目录,我的是D:\Developer\nginx-1.1.14,注意:替换时要小心,有一部分被Nginx Directory标签遮住了,我就搞了半天

现在启动关闭好方便了。

D:\Developer\nginx-1.1.14\conf\nginx.conf 是主要配置文件有点像httpd.conf,结合node.js使用时需要修改该文件,在server {下添加

        location /node {
            proxy_pass http://127.0.0.1:1337;
        }

node,js例子example.js文件如下:

var http = require('http');http.createServer(function (req, res) {  res.writeHead(200, {'Content-Type': 'text/plain'});  res.end('Hello World\n');}).listen(1337, "127.0.0.1");console.log('Server running at http://127.0.0.1:1337/');

在命令行执行node example.js

重启nginx

在地址栏输入http://localhost/node


OK结合使用成功。

原创粉丝点击