Nginx nối ​​thêm đường dẫn được đưa ra trong URI


8

Tôi đang cố gắng định cấu hình phpMyAdmin vì vậy tôi đã đặt vị trí chảy trong Nginx tuy nhiên nó sẽ gửi "pma" vào thư mục gốc:

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"

Cấu hình:

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

}

Có vẻ như đây là vì chỉ thị "gốc", thay vào đó là "bí danh", tuy nhiên sau khi thay đổi này, tôi nhận được:FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client:..."
HTF

Bảng quản trị là lạc đề.
HoplessN00b

Câu trả lời:


8

Tôi đang cố gắng định cấu hình phpMyAdmin vì vậy tôi đã đặt vị trí chảy trong Nginx tuy nhiên nó sẽ gửi "pma" vào thư mục gốc

Bởi vì đó là ... cách thức roothoạt động của chỉ thị.

Nếu bạn muốn sử dụng rootchỉ thị bên trong locationkhối, bạn phải chỉ định một URI giống như tên thư mục và loại bỏ nó khỏi root, một cái gì đó như thế này:

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

Nếu bạn muốn giữ URI đơn giản hơn, hãy sử dụng aliaschỉ thị thay thế:

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

Cảm ơn đã giải thích tuy nhiên tôi vẫn nhận được lỗi sau : 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". Tôi thích Nginx nhưng bí danh đơn giản cho thư mục con khá phức tạp so với Apache
HTF

Gửi cấu hình đầy đủ hiện tại của bạn.
lượng tử

1. Loại bỏ ^~khỏi location ^~ /pma. 2. Đặt khối vị trí này phía trên location ~ \.php$.
lượng tử
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.