Nginx One domain multiple apps

nginx

I'm relatively new to the nginx world, now i have a very complex problem (from my point of view). Here my scenario. I have developed a web application (a single page app based on backbone.js) and for the content pages (imprint and that stuff) I'm using WordPress. I want to achieve the following result:

If the user hits my site (example.com) the index.html of the app should be served with all the JavaScript stuff. If the user clicks a link in the footer for example example.com/imprint the content-page of WordPress should be loaded.

I achieved it to access the app via my main-domain example.com, but all the sub-pages which should be served from WordPress are only showing "File not found" and the nginx.log tells me:

2013/09/26 23:08:03 [error] 31223#0: *86944 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 91.114.231.224, server: www.example.at, request: "GET /trainer/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.example.at"

Due to the fact that the app is also available on facebook, it can be also reached under app.example.com. So i tried to proxy pass every request to the root of example.com to app.example.com. This works fine, but as mentioned with that configuration WordPress wont work any longer.

Here is my current config-file (after the input from @Pothi Kalimuthu)

server {
  server_name www.domain.at domain.at;
  # other directives, such as
  index index.html;

  error_log /var/www/log/error.log debug;

  root /var/www/temp;

  location = / {
    # process the single page apps
    #proxy_pass http://mdev.domain.at/;
    # or
    #try_files $uri $uri/ /index.html;
  }

  location /shared 
  {
      root /var/www/temp/src;
  }

  location / {
    # let's process WordPress here

    # if WordPress is installed in another location, then
    alias /var/www/web/;

    try_files $uri $uri/ /index.php;

    # process PHP here
    location ~* ^/(.*\.php)$ {
      # directives to process PHP
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
    }
  }
}

I tried around a lot, so please excuse the outcommented lines.

Can you give me any hint how to solve my problem and for example if the proxy pass function is maybe the wrong way to go?

edit
After the input of Pothi Kalimuthu, i managed to get at least my single page app and wordpress working together.

Does anybody have an Idea how to config nginx to get it working with a 3rd zend-framework project only serving URL's which matches domain.at/trainers/ or location ^~ /trainers (i guess)?

edit2

i added the location block for /trainers/ but always the index.html will be served

    location /trainers/
    {
            root /var/www/staging/public;
            #alias /var/www/staging/public;
            index index.php;
            try_files $uri $uri/ /index.php$is_args$args;
    }

Best Answer

Update: A slight modification in your original question should probably work. Please try the following...

server {
  server_name domainname.com;
  # other directives, such as
  index index.html index.php;

  root /path/to/apps;

  location = / {
    # process the single page apps
    # proxy_pass http://...;
    # or
    # try_files $uri $uri/ /index.html;
  }

  location / {
    # let's process WordPress here

    # if WordPress is installed in another location, then
    # alias /path/to/wordpress/;

    try_files $uri $uri/ /index.php;

    # process PHP here
    location ~* ^/(.*\.php)$ {
      # directives to process PHP
    }
  }
}

I hope that helps.