Nginx追加URI中给定的路径


8

我正在尝试配置phpMyAdmin,所以我已经在Nginx中设置了流动位置,但是它将“ pma”附加到了根目录:

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"

配置:

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

}

看来这是因为“ root”指令应该改为“ alias”,但是在更改之后,我得到:FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client:..."
HTF 2012年

管理面板不在主题之列。
HopelessN00b

Answers:


8

我正在尝试配置phpMyAdmin,所以我已经在Nginx中设置了流动位置,但是它会将“ pma”附加到根目录中

因为它是... root指令的工作方式。

如果要rootlocation块内使用指令,则必须指定与目录名称相同的URI并将其从中删除root,如下所示:

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

如果要简化URI,请改用alias指令:

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

感谢您的解释,但是仍然出现以下错误: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"。我喜欢Nginx,但与Apache相比,子目录的简单别名非常复杂
HTF 2012年

发布您当前的完整配置。
量子

1. ^~从中取出location ^~ /pma。2.将此定位块放在上方location ~ \.php$
量子
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.