Php 如何为Ember.js+配置Nginx;Wordpress?
场景是,我想使用Wordpress作为我们的Ember.js前端应用程序的后端API提供程序 js前端需要从根目录提供服务,Wordpress实例理想情况下可以通过子目录访问。例如,在localhost上,它将是Php 如何为Ember.js+配置Nginx;Wordpress?,php,wordpress,nginx,ember.js,Php,Wordpress,Nginx,Ember.js,场景是,我想使用Wordpress作为我们的Ember.js前端应用程序的后端API提供程序 js前端需要从根目录提供服务,Wordpress实例理想情况下可以通过子目录访问。例如,在localhost上,它将是http://localhost和http://localhost/wordpress 在磁盘上,这两个文件分别部署在/srv/http/ember和/srv/http/wordpress中 我试图在Nginx站点上按照示例组装配置: 配置: http { upstream
http://localhost
和http://localhost/wordpress
在磁盘上,这两个文件分别部署在/srv/http/ember
和/srv/http/wordpress
中
我试图在Nginx站点上按照示例组装配置:
配置:
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)(/.*)$;
}
}
}
然而,这显然不是正确的解决方案。
尝试访问地址时http://localhost/wordpress/index.php
我在日志中得到以下信息:
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"
配方不清楚wordpress位置的root
指令放在哪里。我还尝试添加了index.php
,这也没有帮助
(为Ember应用提供服务很好。)从您的问题来看,
位置~\.php$
块似乎仅由WordPress使用。但是,它需要/srv/http
的根,以便在本地路径/srv/http/wordpress
下找到以/wordpress
开头的URI脚本文件
由于有两个位置都使用相同的WordPress根目录,因此将/srv/http
设为默认值(即从服务器
块继承)并移动根目录/srv/http/ember可能会更干净编码>到一个单独的位置/
块中
server {
listen 80;
server_name localhost;
root /srv/http;
location / {
root /srv/http/ember;
index index.html;
try_files $uri $uri/ /index.html?/$request_uri;
}
location /wordpress {
index index.php;
try_files $uri $uri/ /wordpress/index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
}
}
请注意,location/wordpress
中的默认URI是/wordpress/index.php
,而不是原来的/index.php
我已经明确地设置了SCRIPT\u文件名
,因为它可能出现在您的fastcgi.conf
文件中,也可能不出现
fastcgi\u split\u path\u info
已被删除,因为它在您的特定情况下是不必要的,我认为它实际上会破坏WordPress的使用方式。从您的问题来看,location ~\.php$
块似乎仅由WordPress使用。但是,它需要/srv/http
的根,以便在本地路径/srv/http/wordpress
下找到以/wordpress
开头的URI脚本文件
由于有两个位置都使用相同的WordPress根目录,因此将/srv/http
设为默认值(即从服务器
块继承)并移动根目录/srv/http/ember可能会更干净编码>到一个单独的位置/
块中
server {
listen 80;
server_name localhost;
root /srv/http;
location / {
root /srv/http/ember;
index index.html;
try_files $uri $uri/ /index.html?/$request_uri;
}
location /wordpress {
index index.php;
try_files $uri $uri/ /wordpress/index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
}
}
请注意,location/wordpress
中的默认URI是/wordpress/index.php
,而不是原来的/index.php
我已经明确地设置了SCRIPT\u文件名
,因为它可能出现在您的fastcgi.conf
文件中,也可能不出现
fastcgi\u split\u path\u info
已被删除,因为它在您的特定情况下是不必要的,我认为它实际上会破坏WordPress的使用方式