Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I need to serve a large number of websites on the same machine. I'll need to be able to add and remove websites dynamically.

Internally, the web server needs to think that the request arrived from a vhost.

Is it possible to use nginx in the front that will handle requests in the form: example.com/vhost1/some/path and rewrite them to: vhost1.example.com/some/path

Can I do that without configuring DNS for vhost1.example.com?

Do I need to add vhost1.example.com to the hosts name on the machine?


share|improve this question

migrated from stackoverflow.com Oct 14 '09 at 12:38

This question came from our site for professional and enthusiast programmers.

4 Answers 4

If you want to test client connections to the vhost project1.example.com, add it to the /etc/hosts file (or equiv on Windows) on the client:  project1.example.com

And then try loading the URL in your browser.

share|improve this answer

You can add wildcard domain *.example.com (this is possible in BIND, don't know about other DNS servers) and setup nginx vhosts project1.example.com, project2.example.com... This way you don't have to update DNS for each added subdomain!

share|improve this answer
+1, we do this way in our development environment and live happy since 2 years. *.deveoper-name.internal.lan. –  AlberT Oct 14 '09 at 15:46

I'm not quite sure what it is that you are trying to achieve. If it is merely an internal re-mapping, you should be able to use a number of non-DNS related methods to change it. The only reason that you may need to change the DNS records is if this involves redirecting clients from example.com to vhost.example.com instead.

share|improve this answer

I run djbDNS on my internal network (and have done previously for more publicly accessible sites) with a given .TLD and wildcard - so *.localtest would resolves to a given IP, which Apache or thttpd will pick up (with Apache's VirtualDocumentRoot). You would be able to do much the same with nginx as well (serve a site based on the HTTP_HOST).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.