title: Apache and ultimate config for nginx to serve all virtual hosts in the right way
body: <p>I've just set up nginx to serve static request on one site, but I have lots of sites on my server and I wonder, should I right new nginx server configuration for all of them?
  What I'm doing now. I have file with all virtual hosts entries for Apache with some-thing like this:</p>
  
  <pre><code>NameVirtualHost *:8080
  &lt;VirtualHost *:8080&gt;
   ServerName sky2high.net
   DocumentRoot /home/mainsiter/data/www/sky2high.net
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:8080&gt;
   ServerName surdo.asmon.ru
   DocumentRoot /home/surdo/data/www/surdo.asmon.ru
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:8080&gt;
   ServerName surdoserver.ru
   DocumentRoot /home/surdo/data/www/surdoserver.ru
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>I have this in apache's ports.conf:</p>
  
  <pre><code>Listen 8080
  </code></pre>
  
  <p>And so I've set up nginx to work with one site (sky2high.net), created next configure file (/etc/nginx/sites-enabled/sky2high.net):</p>
  
  <pre><code>server {
   listen 80;
   server_name sky2high.net www.sky2high.net;
    proxy_pass http://127.0.0.1:8000;
     proxy_set_header Host $host;
  
   access_log /var/log/nginx.access_log;
  
   location ~* \.(jpg|jpeg|gif|png|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|xml|docx|xlsx)$ {
    root /home/mainsiter/data/www/sky2high.net/;
    index index.php;
    access_log off;
    expires 30d;
   }
   location ~ /\.ht {
    deny all;
   }
   location / {
    proxy_pass http://127.0.0.1:8080/;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-for $remote_addr;
    proxy_set_header Host $host;
    proxy_connect_timeout 60;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_redirect off;
    proxy_set_header Connection close;
    proxy_pass_header Content-Type;
    proxy_pass_header Content-Disposition;
    proxy_pass_header Content-Length;
   }
  } 
  </code></pre>
  
  <p>And it works fine for this domain, but of course another virtual hosts are broken.</p>
  
  <p>So, the question is: is there ultimate config option for nginx, witch can help to handle all request, from all virtual hosts (domains) and serve them in the right way? I mean, option that allows not to write separete configure files for each virtual hosts (with all this doubled stuff like root and index options), but only one for all virtual hosts?</p>
  
  <p>PS: should I move question to serverfault?</p>
  
  <p>UPDATE:
  Emm.. I wonder how is it works, but it is. I've made next config files:</p>
  
  <p>/etc/nginx/nginx.conf</p>
  
  <pre><code>user www-data;
  worker_processes  2;
  
  error_log  /var/log/nginx/error.log;
  pid        /var/run/nginx.pid;
  
  events {
      worker_connections  1024;
  }
  
  http {
      include       /etc/nginx/mime.types;
      default_type  application/octet-stream;
  
      access_log  /var/log/nginx/access.log;
  
      sendfile        on;
      #tcp_nopush     on;
  
      #keepalive_timeout  0;
      keepalive_timeout  65;
      tcp_nodelay        on;
  
      gzip             on;   
      gzip_min_length  1000;
      gzip_proxied     any;
      gzip_disable     "msie6";
  
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
  }
  </code></pre>
  
  <p>and </p>
  
  <p>/etc/nginx/sites-enabled/default</p>
  
  <pre><code>server {
      listen 80;
  
      location / {
          proxy_pass http://127.0.0.1:8080/;
          proxy_redirect off;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Connection close;
          proxy_pass_header Content-Type;
          proxy_pass_header Content-Disposition;
          proxy_pass_header Content-Length;
      }
  }
  </code></pre>
  
  <p>I do not understand how is it works, but it is...</p>
  
  <p>UPDATE 2: or it doesn't work! I've looked to "top" in console and metioned that apache serves not only php request, but for static content either =(</p>