title: NGINX multiple server blocks with reverse proxy
body: <p>I am running nginx+PHP+MySQL, and tomcat+postresql on windows (i know its not a very good use of resources, i just need them all for certain projects).</p>
  
  <p>and i need a little help with the nginx config.
  i eventually plan on running nginx on port 80 where wiki.example.com and site.example.com are the same IP.
  but i would like to forward requests for site.example.com to tomcat at localhost:8080, and requests for wiki.example.com will be served by nginx.</p>
  
  <p>i know where my problem lies in the config, only because i can see the error in the console; i cant set two "location /" settings even if they are in different server blocks. here is my config, does anyone know how to fix it?</p>
  
  <pre><code>http {
  include       mime.types;
  default_type  application/octet-stream;
  
  server {
  listen 8080 default_server;
  server_name _;
  server_name_in_redirect off;
  root  www/html;
  }
  
  server {
      listen       wiki.example.com:8080;
      server_name  wiki.example.com;
  
      location / {
          #proxy_pass http://localhost:80/;
          #proxy_set_header  Host $http_host;
          root   www/wiki;
          index  index.html index.htm index.php;
      }
  
      location ~ .php$ {
          root           www/wiki;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include        fastcgi_params;
          index index.php;
      }
  
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   html;
      }
  
  server {
      listen site.example.com:8080;
      server_name site.example.com;
      root www/html;
  
      location / {
          proxy_pass http://localhost:80/;
          proxy_set_header  Host $http_host;
          root   www/html;
          index  index.html index.htm index.php;
      }
  
      }
  
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>thank you very much for your help. i have edited the config per your instruction and it mostly works!! :)
  navigating to site.example.com will load the site (proxied by nginx and served via tomcat)</p>
  
  <p><strong>BUT</strong> navigating to wiki.example.com will produce an nginx 404 message, but navigating to wiki.example.com/index.php?title=Main_Page will load mediawiki as normal.
  so it seems that the defaults are messed up for the wiki server block.</p>
  
  <p><code>
  http://pastebin.com/znT8q6WQ
  </code></p>
  
  <p>does this look like the part with the error?</p>