我安装了 nginx 和 phpmyadmin。我使用以下参数设置了一个域来测试 phpmyadmin:
server {
listen 80;
server_name example.com;
root /usr/share/phpmyadmin;
index index.php;
fastcgi_index index.php;
location ~ \.php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
一切正常(如果我访问域名,我可以登录 phpmyadmin)。问题是它只是为了测试 phpmyadmin,现在我想将其移动到我的“默认”站点。但我不知道如何将其放在 /phpmyadmin 上。这是“默认”nginx 站点的配置(我想将此 /phpmyadmin 位置放在那里):
server {
server_name blabla;
access_log /var/log/nginx/$host.access.log;
error_log /var/log/nginx/error.log;
root /var/www/default;
index index.php index.html;
location / {
try_files $uri $uri/ index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
### NginX Status
location /nginx_status {
stub_status on;
access_log off;
}
### FPM Status
location ~ ^/(status|ping)$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
access_log off;
}
}
答案1
尽管听起来很奇怪,但就我而言,“标准”配置对 phpMyAdmin 不起作用。
这是我最终做的事情,现在可以成功在“/phpmyadmin”上运行:
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
我不是一个经验丰富的管理员,并且这部分配置需要清理,但我希望它是一个好的开始。
答案2
phpmyadmin 没有什么特别之处;标准的 PHP 位置块就足够了:
location /phpmyadmin {
root /usr/share/phpmyadmin;
location ~ \.php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}