我得到了一个带有核心的 PHP 应用程序/srv/myapp/src/www
。
该应用程序可以有插件/srv/myapp/plugins/pluginname
。
插件的入口点是/srv/myapp/plugins/pluginname/www
,对应的url是这样的/pluginname/?arg=value
。
我不知道如何用它获取有效的 nginx 配置。我的基础是:
server {
listen 80;
server_name localhost;
root /srv/myapp/src/www;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
它对所有与核心相关的 URL 都运行良好。
我尝试为给定的插件添加以下内容:
location /plugins/movies {
alias /srv/myapp/plugins/movies/www;
try_files $uri /plugins/movies/index.php?$args;
}
它确实可以为静态内容(js 资产等)提供服务,但任何 URL 都会/plugins/movies/?id=12
给出
2016/12/09 15:12:25 [error] 20491#0: *534 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.42.1, server: localhost, request: "GET /plugins/movies/index.php?id=12 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
我该如何配置 nginx 使其工作?
答案1
输入的文件名总是附加到或+路径try_files
的末尾。alias
root
location
因此,根据您的配置,URL/plugins/movies/index.php?id=2
将对应于/srv/myapp/plugins/movies/www/plugins/movies/index.php?id=2
。
一个快速但不太优雅的修复方法是使用location
如下块:
location /plugins/movies {
alias /srv/myapp/plugins/movies/www;
try_files $uri ../index.php?$args;
}
答案2
FWIW 这是我修复它的方法:
location /plugins/movies {
alias /srv/myapp/plugins/movies/www;
try_files $uri $uri/ index.php;
}
location ~ /plugins/movies/(.*\.php)$ {
alias /srv/myapp/plugins/movies/www/$1;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}