nginx and node.js配合使用 helloworld
2011-08-24 09:39
661 查看
nginx是最好的反向代理服务器。
node.js是。。。 好吧 ,不介绍了,猛击这里
现在小介绍下怎么用nginx和node.js配合使用。
先写个helloworld.js
node.js是。。。 好吧 ,不介绍了,猛击这里
现在小介绍下怎么用nginx和node.js配合使用。
先写个helloworld.js
var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('hello world\n'); }).listen(8000); console.log('Server running at ' target='_blank'>http://127.0.0.1:8000/');[/code]
然后用node helloworld.js指令开启,这样跑在本地的机子的nodejs的程序就算开起来了,占用的是8000端口,可自己修改。
接着,我们在nginx的vhost.conf里面写一个serverserver { listen 80; server_name taqing.me www.taqing.me; location / { proxy_pass http://127.0.0.1:8000; } }
将网站域名设置好,然后端口设置为80,最后proxy_pass设置为http://127.0.0.1:8000,将所有从taqing.me:80的请求传递到nodejs程序去。
重启nginx
访问域名,就可以了看到helloworld了。
虽然node.js本身就可以做服务器是没错啦,比如welcome.js里面设置为80端口就可以了。
但是一个机子跑多个网站,其他网站又是用别的服务器,在80端口已经被占用的情况下,是可以用代理到别的端口来处理的。
相关文章推荐
- nginx and node.js配合使用 helloworld
- nginx and node.js配合使用 helloworld
- nginx and node.js配合使用实现域名绑定
- 使用Node.js配合Nginx实现高负载网络
- 使用Node.js配合Nginx实现高负载网络
- nginx + node.js配合使用
- Centos 7 上使用nginx为Node.js配置反向代理时错误:(13: Permission denied) while connecting to upstream
- 如何使用Node.js在Ubuntu上写一个HelloWorld程序
- 【转】NodeJS on Nginx: 使用nginx反向代理处理静态页面
- 使用MsgPack配合Qt应用程序和node.js应用程序的数据传输
- Node.js中间件和spring boot配合使用
- nginx结合node.js安装使用
- Node.js程序配置使用Nginx服务器(2017.11.17添加https)
- ubantu配置nginx绑定域名以及与node.js的相互配合
- Node.js站点使用Nginx作反向代理时配置GZip压缩的教程
- 安装使用Mongoose配合Node.js操作MongoDB的基础教程
- 使用Meteor配合Node.js编写实时聊天应用的范例
- 如何在 Ubuntu 上使用 pm2 和 Nginx 部署 Node.js 应用
- SilverLight的Helloworld(使用CreateSilverlight.js and Silverlight.js进行SilverLight开发)
- NodeJS on Nginx: 使用nginx反向代理处理静态页面