搞了好久,还是没用。
<code>server { listen 80; server_name localhost; root /home/wwwroot; index index.html index.htm index.php; location /pma { root /home/wwwroot; index index.php; } location ~ ^/pma/.*\.(php|php5)$ { root /home/wwwroot; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } location ~ \.php$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; include fastcgi_params; } } </code>
在fastcgi_params里有
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
搞了好久,还是没用。
<code>server { listen 80; server_name localhost; root /home/wwwroot; index index.html index.htm index.php; location /pma { root /home/wwwroot; index index.php; } location ~ ^/pma/.*\.(php|php5)$ { root /home/wwwroot; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } location ~ \.php$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; include fastcgi_params; } } </code>
在fastcgi_params里有
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
我的做法是配置好 PHP 之后,直接到 DOCUMENT_ROOT 下建立一个到 PMA 的软链接。
<code class="lang-bash">[16:56] caiknife@caiknife-ThinkPad-T400:/usr/share/nginx/html > ll 总用量 12K -rw-r--r-- 1 root root 537 5月 13 2013 50x.html lrwxrwxrwx 1 caiknife caiknife 43 9月 30 09:49 cakestrap -> /home/caiknife/source/cakestrap/app/webroot -rw-r--r-- 1 root root 612 5月 13 2013 index.html -rwxrwxrwx 1 caiknife caiknife 17 9月 21 10:52 phpinfo.php lrwxrwxrwx 1 caiknife caiknife 21 9月 22 10:18 phpmyadmin -> /usr/share/phpmyadmin lrwxrwxrwx 1 caiknife caiknife 21 10月 12 18:27 pma -> /usr/share/phpmyadmin </code>
之后直接访问子目录就可以了。
按照题主的思路,我做了下面这个配置:
<code class="lang-nginx">location /p { root /usr/share/phpmyadmin; index index.php; } location ~ ^/p/.*\.(php|php5)$ { root /usr/share/phpmyadmin; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } </code>
重启 nginx 后,访问 http://localhost:81/p , 得到了 404 页面。我的 nginx 端口监听的是 81 ,80端口留给了 apache 。
为什么会报错 404 ?看一下错误日志:
<code class="lang-log">2013/12/13 23:17:55 [error] 5276#0: *1 open() "/usr/share/phpmyadmin/p" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /p HTTP/1.1", host: "localhost:81" </code>
从 log 中看出,你重写了 root 之后,访问 phpmyadmin 的子目录时,实际上访问的物理路径是 DOCUMENT_ROOT + 'phpmyadmin' 。
OK,那么我再建立一个软链接吧。
<code class="lang-bash">$ sudo ln -s /usr/share/phpmyadmin/ /usr/share/phpmyadmin/p </code>
现在访问正常了。
多麻烦的事情,本来一个软链接就能搞定的事情,现在要两个配置+一个软链接才能搞定,多次一举。