dimanche 1 mai 2016

How to configure Nginx for Ember.js + Wordpress?

The scenario is that I'd like to use Wordpress as a backend API provider for our Ember.js frontend app.

The Ember.js frontend needs to be served from the root, and the Wordpress instance ideally would be reachable by going to a subdirectory. So for example on localhost it would be http://localhost and http://localhost/wordpress

On the disk the two are deployed in /srv/http/ember and /srv/http/wordpress respectively.

I was trying to assemble the configuration going by the example on the Nginx site: http://ift.tt/1j5qazv

The config:

http {

    upstream php {
      server   unix:/run/php-fpm/php-fpm.sock;
    }

    server {
        listen 80;
        server_name localhost;
        root /srv/http/ember;
        index index.html;
        try_files $uri $uri/ /index.html?/$request_uri;

        location /wordpress {
            root /srv/http/wordpress;
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            include fastcgi.conf;
            fastcgi_intercept_errors on;
            fastcgi_pass php;
            fastcgi_split_path_info ^(/wordpress)(/.*)$;
        }

    }

}

However this is obviously not the correct solution. Upon trying to access the address http://localhost/wordpress/index.php I get the following in the logs:

2016/05/01 17:50:14 [error] 4332#4332: *3 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /wordpress/index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.sock:", host: "localhost"

The recipe isn't clear about where to put the root directive for the location of wordpress. I also tried with adding index index.php, which doesn't help either.

(Serving the Ember app works fine.)




Aucun commentaire:

Enregistrer un commentaire