Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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;
    }
share|improve this question
    
Adding another location /trainers/ {} is probably what you need. –  Pothi Sep 27 '13 at 11:15
    
i tried it with the additional location but instead the index.html of the spa is served –  crebuh Sep 27 '13 at 14:13
    
Few thoughts to share on the latest location block... 1. Please avoid using index directive inside a location. Ref: wiki.nginx.org/Pitfalls#Multiple_Index_Directives 2. Also avoid using root inside location block. Ref: wiki.nginx.org/Pitfalls#Root_inside_Location_Block 3. Correct way to use try_files inside a location /somedir/ is try_files $uri $uri/ /somedir/index.php$whatever; I hope that helps! –  Pothi Sep 27 '13 at 14:19

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
I missed a semicolon in one directive! –  Pothi Sep 27 '13 at 1:14
    
First of all thank you for the fast response. I tried to modify the template but without success. Maybe I didn't explain the end result I' m looking for quite well. I want to achieve the following: - root =/ (example.com) should be the single page app (1 single html file location in /var/www/temp - every other route like (example.com/jobs) should be served by wp From my point of view the template assumes that I want to have a structure like "example.com/blog/jobs" is this right? –  crebuh Sep 27 '13 at 5:33
    
My template assumes that your application is served at example.com and your blog is installed at example.com/wpblog . If you'd want every other route like example.com/jobs to be served by WP, then where would you have the home page of the WordPress? –  Pothi Sep 27 '13 at 5:43
    
To provide you more info... WordPress, if accessed with example.com/index.php, would throw a 301 to access it from example.com . In your use case, example.com would be served by the JS application. –  Pothi Sep 27 '13 at 6:00
    
It is not necessary or let's say not desired, that the user can access the homepage of WordPress. Wordpress is only needed for other subpages like mentioned (example.com/jobs). You can say that the homepage of Wordpress is beeing replaced by the single page app. –  crebuh Sep 27 '13 at 6:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.