我试图通过在Ubuntu 10.10与Nginx的apt上安装的phpmyadmin软件包,虽然我最终得到它的工作,我不认为我做得很对:
server { listen 80; ## listen for ipv4 server_name vpsnet.dev; error_log /home/robin/dev/vpsnet/error.log; access_log /var/log/nginx/vpsnet.access.log; location / { root /home/robin/dev/vpsnet/webroot; index index.php index.html; if (-f $request_filename) { break; } if (!-f $request_filename) { rewrite ^/(.+)$ /index.php?url=$1 last; break; } } location /phpmyadmin { root /usr/share; index index.php index.html; } location ~ ^/phpmyadmin/.*\.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/$fastcgi_script_name; include /etc/nginx/fastcgi_params; fastcgi_param SERVER_NAME $host; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/robin/dev/vpsnet/webroot/$fastcgi_script_name; include /etc/nginx/fastcgi_params; fastcgi_param SERVER_NAME $host; } }
我所说的这个部分特别是这个部分:
location /phpmyadmin { root /usr/share; index index.php index.html; } location ~ ^/phpmyadmin/.*\.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/$fastcgi_script_name; include /etc/nginx/fastcgi_params; fastcgi_param SERVER_NAME $host; }
如果我将root指令设置为/usr/share/phpmyadmin并分别将fastcgi_param SCRIPT_FILENAME为/usr/share/phpmyadmin/$fastcgi_script_name; 我得到一个404。
我想服务器将/phpmyadmin/ URL的一部分传递给fastcgi服务器,但是我对此感到困惑,因为我使用的是Apache,而不是这种情况。
我只是想知道是否有人能够说明这一点,为什么这样做,如果我做错了什么。 一个“完美”的设置将是伟大的,或至less有关如何更好地理解NginXconfiguration的一些信息。
看看是否有效:
location /phpmyadmin { alias /usr/share/phpmyadmin; index index.php index.html; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/$fastcgi_script_name; include /etc/nginx/fastcgi_params; fastcgi_param SERVER_NAME $host; }
你的configuration没有错或任何东西。 不build议使用位于内部的块,因为如果你得到很多的位置块,它开始变得混乱(所以最好每个服务器块有一个根),但这不是你的情况,并且fastcgi设置通常在更广方式(所有PHP请求)。