Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subdomains in localhost #18

Closed
RaghavendhraK opened this issue Aug 22, 2016 · 1 comment
Closed

Subdomains in localhost #18

RaghavendhraK opened this issue Aug 22, 2016 · 1 comment

Comments

@RaghavendhraK
Copy link

This is our code

var express = require('express');
var vhost = require('vhost');

var app = express();
app.use(vhost('mail.example.com', function(req, res){
  res.send('I am mail.example.com');
}));
app.use(vhost('*.mail.example.com', function(req, res){
  res.send('I am *.example.com')
}));
app.listen(3000, function(){
  console.log('Listening at port 3000');
});

Our /etc/hosts file contains this line, so that we can start the application in our localhost

127.0.0.1       mail.example.com

When we hit the url 'http://mail.example.com:3000', we do get the response 'I am mail.example.com'.
But when we hit the url 'http://a.mail.example.com:3000', we are getting the 'Server not found' response.
Am I doing anything wrong here?

@RaghavendhraK
Copy link
Author

OK we got this issue. It is nothing to do with vhost. The issue is with /etc/hosts. The line should be

127.0.0.1 *.mail.example.com

But wildcard is not supported in /etc/hosts file. Thus we need to allow the wildcard subdomains with DNS. Please refer http://askubuntu.com/questions/150135/how-to-block-specific-domains-in-hosts-file/150180#150180 for more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant