Nginx /phpmyadmin 目录为默认主机

Nginx /phpmyadmin 目录为默认主机

我的 nginx 服务器出了问题。

我对 nginx 还不熟悉,所以配置文件还不是我最擅长的(目前)

我在 /etc/nginx/conf.d/ 中有这个 default.conf:

server {
    listen       80;
    server_name  _;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        try_files $uri =404;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
    location /phpMyAdmin {
    root /usr/share;
    index index.html index.htm index.php;
    }
    location ~ \.php$ {
        root        /usr/share;
        try_files $uri =404;
        fastcgi_pass unix:/tmp/php5-fpm.sock;
        fastcgi_index       index.php;
        fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include     fastcgi_params;
    }
}

但是当我访问时,<ServerIP>/phpMyAdmin它只给出 404。

日志文件如下:

2012/09/18 19:12:53 [error] 3184#0: *1 open() "/usr/share/phpMyAdmin/nginx-logo.png" failed (2: No such file or directory), client: 1.2.3.4, server: _, request: "GET /phpMyAdmin/nginx-logo.png HTTP/1.1", host: "4.3.2.1", referrer: "http://4.3.2.1/phpMyAdmin/index.php"

我做错了什么?

答案1

以下是我配置的相关代码。我也很难让它正常工作,而且我对 nginx 也是新手。

尝试在位置部分的根声明末尾添加尾部斜杠。

location /phpMyAdmin {
    root /usr/share/;
    index index.php index.html index.htm;
    location ~ ^/phpMyAdmin/(.+\.php)$ {
        try_files $uri =404;
        root /usr/share/;
        fastcgi_pass unix:/tmp/php-fpm.socket;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
        fastcgi_param PATH_INFO $fastcgi_script_name;
    }

    location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
        root /usr/share/;
    }
}

相关内容