简体   繁体   English

静态IP上访问Node.js网站的字符串名称

[英]String name to access nodejs website on static ip

I am working in intranet enviornment, and one machine has a static ip, 10.10.10.10:3000. 我正在Intranet环境中工作,并且一台机器具有静态IP,即10.10.10.10:3000。 I have deployed my nodejs server client on this computer and people in intranet can access it by http://10.10.10.10:3000 . 我已经在这台计算机上部署了我的nodejs服务器客户端,内联网中的人可以通过http://10.10.10.10:3000访问它。 I need to change this to something like http://abawa.alladin.com:3000 , is it possible to do with access to only my machine or do i need some help of IT admin? 我需要将其更改为http://abawa.alladin.com:3000之类的东西,是否可以只访问我的机器,还是需要IT管理员帮助?

我认为您需要联系您的IT管理员,因为您必须在服务器上安装DNS。

You can modify your hosts file. 您可以修改主机文件。

Modifying your hosts file causes your local machine to look directly at the Internet Protocol (IP) address that you specify. 修改主机文件会使本地计算机直接查看您指定的Internet协议(IP)地址。 Rackspace offers managed hosting solutions to assist with the handling of these resources. Rackspace提供托管托管解决方案,以协助处理这些资源。

10.10.10.10 www.domain.com domain.com

https://support.rackspace.com/how-to/modify-your-hosts-file/ https://support.rackspace.com/how-to/modify-your-hosts-file/

windows path c:\\Windows\\System32\\Drivers\\etc\\hosts Windows路径c:\\Windows\\System32\\Drivers\\etc\\hosts

linux or mac /etc/hosts linux或mac /etc/hosts

You can do it using vhost . 您可以使用vhost进行操作

edit /etc/hosts: 编辑/ etc / hosts:

10.10.10.10   abawa.alladin.com:3000

Following is example for vhost with express 以下是带有express vhost示例

/**
* Module dependencies.
*/
var express = require('../..');
var logger = require('morgan');
var vhost = require('vhost');

// Main server app
var main = express();

if (!module.parent) main.use(logger('dev'));

main.get('/', function(req, res){
  res.send('Hello from main app!');
});

main.get('/:sub', function(req, res){
  res.send('requested ' + req.params.sub);
});

// Redirect app
var redirect = express();

redirect.use(function(req, res){
  if (!module.parent) console.log(req.vhost);
  res.redirect('http://abawa.alladin.com:3000/' + req.vhost[0]);
});

// Vhost app
var app = module.exports = express();

app.use(vhost('*.alladin.com', redirect)); // Serves all subdomains via Redirect app
app.use(vhost('alladin.com', main)); // Serves top level domain via Main server app

/* istanbul ignore next */
if (!module.parent) {
  app.listen(3000);
  console.log('Express started on port 3000');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM