node绑定域名 nginx篇

Posted fslnet

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node绑定域名 nginx篇相关的知识,希望对你有一定的参考价值。

创建nodejs文件,并测试执行有没有问题。

var express = require(‘express‘);
var app = express();
 
app.get(‘/‘, function (req, res) 
	res.type(‘text/plain‘);
	res.send(‘node is working‘);
    
)
 
var server = app.listen(3000, function ()  
  var host = server.address().address
  var port = server.address().port 
  console.log("runing")
 
)

  

配置nginx 绑定域名,反向代理。

       upstream nodejs
        server 127.0.0.1:3000;   
        keepalive 64;
        

   server 
         listen 80;
         server_name abl.com;  
         location / 
              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_set_header X-Nginx-Proxy true;
              proxy_set_header Connection "";
              proxy_pass      http://nodejs;
          

  

配置hosts文件 把abl.com指向本地

# localhost name resolution is handled within DNS itself
#	127.0.0.1       localhost
#	::1             localhost
127.0.0.1  abl.com

  

访问指定域名,正常输出内容。如图

 

技术图片

以上是关于node绑定域名 nginx篇的主要内容,如果未能解决你的问题,请参考以下文章

nginx 域名绑定 域名, nginx 域名绑定 端口

nginx 域名绑定 域名, nginx 域名绑定 端口

nginx 域名绑定 域名, nginx 域名绑定 端口

nginx 域名绑定 域名, nginx 域名绑定 端口

nginx 域名绑定 域名, nginx 域名绑定 端口

nginx 域名绑定 域名, nginx 域名绑定 端口