从同一个nginx和乘客服务rails,php和static

I would like to serve rails, php and static html from the same nginx like this:

  • example.com - hits php
  • example.com/app - hits rails
  • example.com/static - hits static

This situation may be temporary (may be split to multiple servers at some point), so I would like to avoid changes to the code (adding scope or namespace to rails routes - I would like rails to treat "example.com/app" as root).

What should my nginx.conf look like?

I used this page from the passenger docs as reference and tried something like this:

server {
  server_name example.com;
  listen 80;

  root /var/www/php;

  try_files $uri =404;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;

  location ~ ^/app(/.*|$) {
    alias /var/www/rails/current/public$1;

    access_log    /var/www/rails/current/log/access.log;
    error_log     /var/www/rails/current/log/error.log;

    passenger_base_uri /app;
    passenger_app_root /var/www/rails;
    passenger_document_root /var/www/rails/currnet/public;
    passenger_enabled on;
    passenger_app_env production;
    passenger_friendly_error_pages on;
    passenger_ruby /usr/local/rvm/gems/ruby-2.1.5@app/wrappers/ruby;

    client_max_body_size 4G;
    keepalive_timeout 10;
  }
}

but I get "not found"

I nearly got it right. I had the wrong passenger_base_uri. This is what finally worked for me:

server {
  server_name example.com;
  listen 80;

  root var/www/php;

  try_files $uri =404;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;

  location ~^/app(/.*|$) {
    alias /var/www/rails/current/public$1;

    access_log    /var/www/rails/current/log/access.log;
    error_log     /var/www/rails/current/log/error.log;

    passenger_base_uri /app;
    passenger_app_root /var/www/rails/current;
    passenger_enabled on;
    passenger_app_env production;
    passenger_friendly_error_pages on;
    passenger_ruby /usr/local/rvm/gems/ruby-2.1.5@app/wrappers/ruby;
  }

  client_max_body_size 4G;
  keepalive_timeout 10;
}