简体   繁体   中英

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. I have deployed my nodejs server client on this computer and people in intranet can access it by 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?

我认为您需要联系您的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. Rackspace offers managed hosting solutions to assist with the handling of these resources.

10.10.10.10 www.domain.com domain.com

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

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

linux or mac /etc/hosts

You can do it using vhost .

edit /etc/hosts:

10.10.10.10   abawa.alladin.com:3000

Following is example for vhost with express

/**
* 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');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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