2016-03-17 55 views
2

我剛剛安裝了nginx,php-fpm和phpmyadmin。 這是我的www文件夾。Nginx沒有重定向到phpmyadmin的index.php頁面

[[email protected] etc]# ll /usr/share/nginx/html/ 
-rw-r--r-- 1 root root 3650 Feb 13 18:45 404.html 
-rw-r--r-- 1 root root 3693 Feb 13 18:45 50x.html 
drwxr-xr-x 3 root root 40 Mar 17 06:14 myapp.eu 
-rw-r--r-- 1 root root 3700 Feb 13 18:45 index.html 
lrwxrwxrwx 1 root root 22 Mar 17 06:52 mysql -> /usr/share/phpMyAdmin/ 

下myapp.conf文件的phpmyadmin我的nginx的conf文件的位置看起來像這樣

location /mysql { 
     alias /usr/share/phpMyAdmin; 
     location ~ \.php$ { 
       index index.php index.html index.htm; 
       include fastcgi_params; 
       fastcgi_param SCRIPT_FILENAME $request_filename; 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       fastcgi_pass 127.0.0.1:9000; 
     } 
} 

問題: 如果我嘗試訪問myapp.eu/mysql我獲得以下的nginx的日誌錯誤

2016/03/17 09:21:01 [error] 2119#0: *28 directory index of "/usr/share/phpMyAdmin/" is forbidden, client: 84.52.168.135, server: euro-swap.eu, request: "GET /mysql/ HTTP/1.1", host: "euro-swap.eu" 

但是,如果我嘗試訪問myapp.eu/mysql/index.php phpmyadmin顯示。所以我猜,nginx應該以某種方式重定向到index.php頁面。

是什麼導致了這個問題?如何解決它?如果您需要任何其他信息,請讓我知道,我會提供。

回答

2

當你試圖打開myapp.eu/mysql,其由外location指令逮住。但是沒有爲外層定義索引。因此,解決方案是從內location有移動索引指令:

location /mysql { 
     alias /usr/share/phpMyAdmin; 
     index index.php index.html index.htm; 

     location ~ \.php$ { 
       include fastcgi_params; 
       fastcgi_param SCRIPT_FILENAME $request_filename; 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       fastcgi_pass 127.0.0.1:9000; 
     } 
} 
1

問題出在第二個位置。 location ~ \.php$匹配以.php結尾的路徑,而您的路由不是:/mysql。嘗試刪除它。

location /mysql { 
    alias /usr/share/phpMyAdmin; 
    index index.php index.html index.htm; 
    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $request_filename; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass 127.0.0.1:9000; 
} 
1

這裏是我的一個子域運行phpMyAdmin的解決方案。

再加下一次,我有這個問題,我知道我將能夠複製/粘貼自己的解決方案:)

server { 
    listen 80; 
    server_name secret-sql-subdomain.site.com; 
    root /usr/share/phpMyAdmin; 
    location/{ 
     fastcgi_pass php-fpm; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 
相關問題