我有一个包装在 Wordpress 小部件中的 Web 应用程序(simpleSAML.php),它需要提供如下路径:
http://example.com/wp-content/plugins/saml-20-single-sign-on/saml/www/module.php/saml/sp/metadata.php/1
我的 Wordpress nginx 配置运行正常,但需要提供上述复杂路径的部分却不行。它返回“文件未找到”并在 nginx 日志中发布“主脚本未知”错误。
以下是我在 vhost 配置中的内容:
server {
listen 80 default;
server_name *.example.com example.com;
root /srv/web/wpmulti;
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
index index.html;
location / {
index index.html index.htm index.php;
include global/restrictions.conf;
include global/wordpress-ms-subdir.conf;
rewrite ^ http://example.com$request_uri permanent;
}
location /wp-content/plugins/saml-20-single-sign-on/saml {
alias /srv/web/wpmulti/wp-content/plugins/saml-20-single-sign-on/saml/www;
location ~* /saml/(?<script>.+?\.php.*)(?<pathinfo>.*)?$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_NAME /saml/$script;
fastcgi_param SCRIPT_FILENAME $document_root$script;
fastcgi_param PATH_INFO $pathinfo;
}
}
location ~ /wp-content/plugins/saml-20-single-sign-on/saml(.*) {
autoindex on;
alias /srv/web/wpmulti/wp-content/plugins/saml-20-single-sign-on/saml/www/$1;
}
location ~ ^/wp-content/plugins/saml-20-single-sign-on/saml/(.*) {
alias /srv/web/wpmulti/wp-content/plugins/saml-20-single-sign-on/saml/www/$1;
}
}
这是由我们办公室安装的 simpleSAML.php 和网络上其他人找到的旧解决方案拼凑而成的。
我整天都在仔细阅读 nginx 文档,但似乎找不到解决方案。我的配置出了什么问题?
答案1
经过一天的头痛,我解决了这个问题。这是修复该问题的 vhost 配置。
server {
listen 80 default;
server_name *.example.com example.com;
root /srv/web/wpmulti;
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
index index.html;
location / {
index index.html index.htm index.php;
include global/restrictions.conf;
include global/wordpress-ms-subdir.conf;
rewrite ^ http://example.com$request_uri permanent;
}
location ^~ /wp-content/plugins/saml-20-single-sign-on {
location ~ ^(?<script_name>.*?\.php)(?<path_info>/.*)?$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param PATH_TRANSLATED $document_root$path_info;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
}