Hey guys anyone here know how to set-up virtual host on nginx? ive tried the manuals but doesn't work for me

What is not working for you? Have you tried these:

- http://wiki.nginx.org/VirtualHostExample
- http://library.linode.com/web-servers/nginx/configuration/basic
- http://articles.slicehost.com/2009/9/1/debian-lenny-nginx-virtual-hosts-1

If you are testing on local then you have to edit /etc/hosts file, adding a new line with something like:

127.0.0.1 virtual_domain_host.tld

Where virtual_domain_host.tld is the choosen server_name, otherwise you need to register your domain to a DNS server.

@cereal hey dude thanks for the reply.... yes im using localhost were gonna be developing some php project on nginx soon so i wanna 1st familiarize myself on this, i've managed to run php and mysql now i want to learn how to add virtual host. yes i already done that on the host file, 127.0.0.1 gecko.local, actually i know how to create virtual host, but on apache not on nginx. After adding the servername on the hostfile, i updated the nginx.conf file and entered some server block, but i only managed to call the servername which is gecko.local but it's not pointing to the subdirectory i want it to point, it still pointing at the root folder.
my directory hierarchy is like this (ill show you an absoulute path)
C:/nginx/html/ <----- this is the root right
C:/nginx/html/gecko/ <--- this is the directory i want my virtual host to point
now on my nginx.conf i added inside the http block

server {
        listen       80;
        server_name  gecko.local;

        location / {
            root   html/gecko; #i also tried absolute path C:/nginx/html/gecko
            index  index.php;
        }
    }

i also tried this

server {
  listen          80;
  server_name     gecko.local
  index           index.php
  root            html/gecko;
}

also this

server {
  listen          80;
  server_name     gecko.local;
  rewrite ^       http://gecko.local$request_uri? permanent;
 }

I can't try on a Windows box right now, but you have to set an absolute path, as you already did and reload the server. Check your nginx PHP config, maybe you set another root for PHP scripts? http://wiki.nginx.org/PHPFastCGIOnWindows

And try to open a simple index.html page before trying to point to index.php so change directive index to search for index.html first. You can also set error and access logs, that will be helpful, you can see where the pages are currently opened. Bye :)

@cereal ha ha yeah man i already done that setting it in absolute path, then restarting the server, the php for php-cgi works fine, it's PHP scripts. well thanks for the reply anyways, ill try to figure out this myself then :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.