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

if I don't have an domain and what I have is IP address.. how can I create a virtual host? can someone give me an example of a nginx.conf file?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Use hosts file. Add server directive to nginx config:

server {
    server_name   example.com;
    root /var/www/example.com;
}

Create /var/www/example.com:

# mkdir /var/www/example.com
# echo "example.com virtualhost" >> /var/www/example.com/index.html

Add example.com to your local system hosts files(%SystemRoot%\system32\drivers\etc\ in Windows):

#echo "IP example.com" > /etc/hosts

Also you can use DynDNS.

share|improve this answer
    
so then to access example.com I can do IP/example –  EquinoX Feb 28 '11 at 6:21
    
No. You need use DNS name. Web bowser add Host header when you use DNS name. Nginx use Host header to route virtual hosts. –  ooshro Feb 28 '11 at 6:22
    
can you show what you mean by that? –  EquinoX Feb 28 '11 at 6:27
    
Create example.com and www.example.com virtual hosts with different content. Then open "example.com" and "www.example.com", you see different web site. –  ooshro Feb 28 '11 at 6:29
    
well...I want to be able to access it from outside the server –  EquinoX Feb 28 '11 at 6:35

You either need to use a non name based virtual host at which point you can only have one site per IP address, in this case you can just type the IP into your webbrowser. The default nginx config on most systems should already have this setup for you

If you want to put more than site on an IP you have to use name based virtualhosts, you set these up as normal if you did have a domain name, but to be able to see them you would have to edit your hosts file to add the domain records you set your virtualhosts on. You would have to do this on every computer you want to access those sites from and it does require admin privileges to each machine

NOTE: you dont actually need to own the domains you use, but i would recommend it or at least not using common domains

share|improve this answer

Your Answer

 
discard

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.