创建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

  

posted on 2022-06-15 18:26  chenlw101  阅读(567)  评论(0编辑  收藏  举报