Ubuntu - Nginx 中的安全性 PHPMyAdmin

Ubuntu - Nginx 中的安全性 PHPMyAdmin

我按照該網站上的說明進行操作安裝 PHPMyAdmin。但是,此配置適用於 Apache,而我使用的是 Nginx。我在網路上找不到任何有關如何限制允許存取 PHPMyadmin 的 IP 位址的教學。

有人可以推荐一個網站或告訴我如何做到這一點嗎?

編輯

這是我目前的 Nginx 設定:

server {
        listen   80;

        root /usr/share/nginx/html/cl2g/public/;
        index index.php index.html index.htm;

        server_name schedulium.ca;

        # AnuglarJS UI Front /index.html
        location / {
                rewrite ^/(.*)/$ /$1 redirect;
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.html
                        break;
                }
        }

        # PHPMyAdmin
        location /phpmyadmin/ {
                allow my-ip-address;
                deny all;

                rewrite ^/(.*)/$ /$1 redirect;
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /phpmyadmin/index.php;
                }
        }


        # Laravel Back-end /api/index.php
        location /api/ {
               # try_files $uri $uri/ /index.php$is_args$args;
                rewrite ^/(.*)/$ /$1 redirect;
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /api/index.php;
                }
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/html;
        }

        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        # stfu
        location ~ \.php$ {
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

}

答案1

在 Nginx 中,您可以在網站檔案中設定參數,而不是透過 htaccess。

在 /etc/nginx/sites-enabled/ 中編輯對應的網站文件

如果您的位置看起來像這樣。

location /phpmyadmin {
....
}

新增以下內容

allow 192.168.0.2/32; 
deny all;

這將只允許存取IP 192.168.0.2的主機

然後重新啟動/重新載入 Nginx。

答案2

如果您已按照您放置連結的教學進行操作,則您正在使用 .htaccess 進行 IP 限制。在 Nginx 中你可以使用 nginx.conf:

server {
listen 80;
server_name name;

location / {
  root /phpmyadmin;
  passenger_enabled on;

  allow   your-public-ip;
  deny    all;
}
}

當然,您必須更改此設置,以便它與您的 IP 位址一起使用。

預設情況下 PHPMyAdmin 安裝在/usr/share/phpmyadminUbuntu 中。應該phpMyAdmin.conf有一個選項只允許您的 IP。

所以你可以透過 Nginx 或 PHPMyAdmin 來完成。

相關內容