分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

nginx使用反向代理支持node.js服务

发布时间:2023-09-06 01:29责任编辑:胡小海关键词:js反向代理nginx

前言

Node.js自身能作为web服务器用,但是如果要在一台机器上开启多个Node.js应用该如何做呢?有一种答案就是使用nginx做反向代理。反向代理在这里的作用就是,当代理服务器接收到请求,将请求转发到目的服务器,然后获取数据后返回。

步骤

一、正常使用node.js开启web服务

var http = require(‘http‘);http.createServer(function (request, response) { ???response.writeHead(200, {‘Content-Type‘: ‘text/plain‘}); ???response.end(‘hello world\n‘);}).listen(1337);console.log(‘Server running at http://127.0.0.1:1337/‘);

二、为域名配置nginx

[root@iZ25lzba47vZ vhost]# lsdefault.conf ??????????????node.ruanwenwu.cn.conf ?test.ruanwenwu.conf ???www.tjzsyl.com.conflaravel.ruanwenwu.cn.conf ?wss.ruanwenwu.cn.conf ?www.tjzsyl.com.conf.bak[root@iZ25lzba47vZ vhost]# pwd

node.ruanwenwu.cn.conf:

server{ ???listen 80; ???server_name node.ruanwenwu.cn; ???location / { ???????proxy_pass http://127.0.0.1:1337; ???}}

步骤很简单,这些就可以了。

最后看一下我们的效果:http://node.ruanwenwu.cn

nginx使用反向代理支持node.js服务

原文地址:http://www.cnblogs.com/doubilaile/p/8017463.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved