title: How to put multiple websites on a localhost port 80 using nginx.conf file?
body: <p>I used nginx to setup a virtual server and have a <code>nginx.conf</code> file as below, which works fine for two different websites on <code>http://localhost</code> and <code>http://localhost:100</code>:</p>
  
  <pre><code>user  nobody;
  worker_processes  1;
  error_log /usr/local/Cellar/nginx/1.4.6/logs/error.log;
  pid       /usr/local/Cellar/nginx/1.4.6/logs/nginx.pid;
  
  events {
      worker_connections  1024;
  }
  
  http {
      include       /usr/local/etc/nginx/mime.types;
      include       /usr/local/etc/nginx/fastcgi.conf;
      default_type  application/octet-stream;
      access_log    /usr/local/var/log/nginx/access.log;
  
      sendfile        on;
      tcp_nopush     on;
      keepalive_timeout  65;
      gzip  on;
      server {
          listen       80;
          server_name  localhost;
          access_log  /usr/local/Cellar/nginx/1.4.6/logs/localhost.access.log  combined;
  
          location / {
              root   /Users/apiah/Websites/greenapple;
              index  index.html index.htm index.php;
          }
          location ~ \.php$ {
              root           /Users/apiah/Websites/greenapple;
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_index  index.php;
              fastcgi_param SCRIPT_FILENAME /Users/apiah/Websites/greenapple$fastcgi_script_name;
              include        /usr/local/etc/nginx/fastcgi_params;
          }
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {
              root   html;
          }
      }
      server {
          listen       100;
          server_name  localhost;
          access_log  /usr/local/Cellar/nginx/1.4.6/logs/localhost.access.log  combined;
  
          location / {
              root   /Users/apiah/Websites/blueweb;
              index  index.html index.htm index.php;
          }
          location ~ \.php$ {
              root           /Users/apiah/Websites/blueweb;
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_index  index.php;
              fastcgi_param SCRIPT_FILENAME /Users/apiah/Websites/blueweb$fastcgi_script_name;
              include        /usr/local/etc/nginx/fastcgi_params;
          }
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {
              root   html;
          }
      }    
  }
  </code></pre>
  
  <p>I like to test the above two (or more) websites on the same port 80 <code>http://localhost</code>. For example, assume that we have three folders called <code>blueweb</code>, <code>redweb</code> and <code>greenweb</code>, so I want to be able to see all three folders when I go to <code>http://localhost</code> and then from there choose to go to <code>http://localhost/blueweb</code>, <code>http://localhost/redweb</code> or <code>http://localhost/greenweb</code>. Could you please review the <code>nginx.conf</code> file and give me your comments?</p>