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'm trying to configure phpMyAdmin so I've set the flowing location in Nginx however it apends the "pma" to the root directory:

2012/08/14 13:59:49 [error] 10151#0: *2 "/usr/share/phpMyAdmin/pma/index.php" is not found (2: No such file or directory), client: 192.168.1.2, server: domain.com, request: "GET /pma/ HTTP/1.1", host: "192.168.1.24"

Config:

location ^~ /pma {
            root /usr/share/phpMyAdmin;

        location ~ \.php$ {
            root /usr/share/phpMyAdmin;
            fastcgi_pass unix:/var/run/php-fpm/www.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_param HTTPS on;
        }

## HTTP to HTTPS redirect
server {
    listen  80;
    root  /var/empty;
    server_name domain.com;
    rewrite ^ https://domain.com$request_uri permanent;
    }


server {

    listen      443 default_server ssl;
    root        /var/www/html;
    index index.php index.html index.htm;
    server_name domain.com;

    location / {
        try_files $uri $uri/ /index.php?$args;

    }


    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    fastcgi_param HTTPS on;
    }

## phpMyAdmin
    location ^~ /pma  {
    alias /usr/share/phpMyAdmin/;
       try_files $uri $uri/ /index.php;

    location ~ ^/pma(.+\.php)$ {
    fastcgi_pass unix:/var/run/php-fpm/www.sock;
    fastcgi_index index.php;
    alias /usr/share/phpMyAdmin$1;
    fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$1;
    include fastcgi_params;
    fastcgi_param HTTPS on;

    try_files $uri $uri/ /index.php?q=$request_uri;
    }
    }

## deny access to .htaccess files, if Apache's document root concurs with nginx's one
    location ~ /\. {
    access_log off;
    log_not_found off;
    deny  all;
    }

#serve static files directly
location ~* \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|flv|mp3)$ {
    access_log off;
    log_not_found off;
    expires 2w;
    add_header Pragma "public";
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

}
share|improve this question
    
It looks like this is because the "root" directive, it should be "alias" instead however after this change I'm getting: FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client:..." –  HTF Aug 14 '12 at 15:52

1 Answer 1

up vote 5 down vote accepted

I'm trying to configure phpMyAdmin so I've set the flowing location in Nginx however it apends the "pma" to the root directory

Because it is... the way root directive works.

If you want to use root directive inside the location block, you must specify an URI same as the directory name and strip it off from the root, something like this:

    location /phpmyadmin {
        root /usr/share/;
        try_files $uri $uri/ /index.php;

        location ~ ^/phpmyadmin(.+\.php)$ {
            root /usr/share/;
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi.conf;
            fastcgi_intercept_errors        on;
        }
    }

If you want to keep URI simpler, use alias directive instead:

    location /pma {
        alias /usr/share/phpmyadmin/;
        try_files $uri $uri/ /index.php;

        location ~ ^/pma(.+\.php)$ {
            alias /usr/share/phpmyadmin$1;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$1;
            include fastcgi_params;
            fastcgi_intercept_errors        on;
        }
    }
share|improve this answer
    
Thanks for explanation however I'm still getting the following error: 2012/08/15 11:34:43 [error] 20685#0: *526 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.130, server: domain.com, request: "GET /pma/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/www.sock:", host: "192.168.1.24". I like Nginx but simple alias for subdirectory is quite complicated comparing to Apache –  HTF Aug 15 '12 at 10:37
    
Post your current full config. –  quanta Aug 15 '12 at 10:57
    
1. Remove the ^~ from the location ^~ /pma. 2. Put this location block above the location ~ \.php$. –  quanta Aug 16 '12 at 3:05

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.