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 have a web app (simpleSAML.php) wrapped in a Wordpress widget that needs to serve paths like the following:

http://example.com/wp-content/plugins/saml-20-single-sign-on/saml/www/module.php/saml/sp/metadata.php/1

My nginx configuration for Wordpress works fine, but the part that needs to serve the complex path above does not. It returns "File not found" and posts "Primary script unknown" errors in the nginx log.

Here's what I have in the vhost config:

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;
    }

}

This has been cobbled together from a working simpleSAML.php installation at our office and old solutions found by other people around the web.

I've been poring over nginx documentation all day, but I can't seem to find a solution. What's broken in my config?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

After a day of headaches, I solved this issue. Here's the vhost config that fixed it.

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;
        }
    }
}
share|improve this answer

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.