Nginx

配置 nginx 以使所有域都可以 /phpmyadmin

  • May 9, 2017

我正在嘗試設置 nginx,以便每個虛擬主機都可以訪問 phpmyadmin,所以 example.com/phpmyadmin

我嘗試使用此配置,但不走運

,這是我的預設文件

server {
   #return 404;
       location /phpmyadmin {
              root /usr/share/nginx/phpmyadmin/;
              index index.php index.html index.htm;
              location ~ ^/phpmyadmin/(.+\.php)$ {
                      try_files $uri =404;
                      root /usr/share/nginx/phpmyadmin/;
                      fastcgi_pass unix:/run/php/php7.1-fpm.sock;
                      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/nginx/phpmyadmin/;
              }
       }
       location /phpMyAdmin {
              rewrite ^/* /phpmyadmin last;
       }
}

謝謝。

據我所知,nginx 不允許在伺服器之間共享位置。您應該在每個伺服器部分(對於每個域)添加 phpmyadmin 位置,或者配置 nginx 以偵聽其他埠(例如listen 88)並配置 phpmyadmin 的位置,使其在所有域上,但在另一個埠上。

據我所知,您需要location /phpmyadmin {...}為每個伺服器、每個虛擬主機設置這些指令,您不能設置它們一次並且對所有server {}塊都處於活動狀態。

最簡單的可能是創建一個phpmyadmin.include從每個伺服器載入的文件:

# conf/phpmyadmin.conf
location /phpmyadmin {
          root /usr/share/nginx/phpmyadmin/;
          index index.php index.html index.htm;
          location ~ ^/phpmyadmin/(.+\.php)$ {
                  try_files $uri =404;
                  root /usr/share/nginx/phpmyadmin/;
                  fastcgi_pass unix:/run/php/php7.1-fpm.sock;
                  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/nginx/phpmyadmin/;
          }
}
location /phpMyAdmin {
          rewrite ^/* /phpmyadmin last;
}

進而

server { 
 listen       80;
 server_name  example.com www.example.com;
 include      conf/phpmyadmin.conf;
}
server { 
 listen       80;
 server_name  example.org www.example.org;
 include      conf/phpmyadmin.conf;
}

引用自:https://serverfault.com/questions/849045