Nginx 不会重定向到 phpmyadmin 的 index.php 页面
Nginx doesn't redirect to index.php page of phpmyadmin
我刚刚安装了 nginx、php-fpm 和 phpmyadmin。
这是我的 www 文件夹。
[root@vmi67073 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 页面。
是什么导致了这个问题?如何解决?如果您需要任何其他信息,请告诉我,我会提供。
问题出在第二个位置。 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;
}
当您尝试打开 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;
}
}
这是我在子域上针对 运行 phpmyadmin 的解决方案。
此外,下次我遇到这个问题时,我知道我将能够copy/paste我自己的解决方案:)
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;
}
}
我刚刚安装了 nginx、php-fpm 和 phpmyadmin。 这是我的 www 文件夹。
[root@vmi67073 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 页面。
是什么导致了这个问题?如何解决?如果您需要任何其他信息,请告诉我,我会提供。
问题出在第二个位置。 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;
}
当您尝试打开 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;
}
}
这是我在子域上针对 运行 phpmyadmin 的解决方案。
此外,下次我遇到这个问题时,我知道我将能够copy/paste我自己的解决方案:)
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;
}
}