From cdbef8bdc7fa924285f3d7acaf81a43880c0dd29 Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Sun, 3 Nov 2024 18:35:00 +0530 Subject: [PATCH] nginx: configure adminer.local virtual host --- dev-environment/adminer.nix | 60 ++++++++++++++++++++++++ dev-environment/default.nix | 6 ++- dev-environment/mysql.nix | 11 +++++ dev-environment/nginx.nix | 11 +---- home-manager/web-server-html/default.nix | 11 ----- system/network.nix | 15 +++++- 6 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 dev-environment/adminer.nix create mode 100644 dev-environment/mysql.nix diff --git a/dev-environment/adminer.nix b/dev-environment/adminer.nix new file mode 100644 index 00000000..28a6763d --- /dev/null +++ b/dev-environment/adminer.nix @@ -0,0 +1,60 @@ +# Import of thie module is controlled by bool: servicesSettings.nginx +# This is a configuration file for the adminer.local virtual host +# It is a database management tool that is a single PHP file +{ + self, + config, + lib, + pkgs, + servicesSettings, + ... +}: { + # Nginx configuration for adminer.local + # but for this to work, adminer.local must point to "127.0.0.1" + # via networking.extraHosts, you should add to ../system/network.nix + + # To use adminer, just type adminer.local in the browser + # After any changes to this file, run the following commands: + # systemctl restart phpfpm-adminer.service nginx.service + + services.nginx.virtualHosts."adminer.local" = { + extraConfig = '' + index index.php; + ''; + locations."/".extraConfig = '' + try_files $uri $uri/ /index.php?$args; + ''; + + locations."~ ^(.+\\.php)(.*)$" = { + extraConfig = '' + # Check that the PHP script exists before passing it + try_files $fastcgi_script_name =404; + include ${config.services.nginx.package}/conf/fastcgi_params; + fastcgi_split_path_info ^(.+\.php)(.*)$; + fastcgi_pass unix:${config.services.phpfpm.pools.adminer.socket}; + fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + + include ${config.services.nginx.package}/conf/fastcgi.conf; + ''; + }; + root = "${self.packages.${pkgs.system}.adminer-pematon-with-adminer-theme}"; + }; + + # PHP-FPM pool configuration + # Needed for nginx to communicate with PHP + services.phpfpm.pools.adminer = { + user = "nobody"; + settings = { + "pm" = "dynamic"; + "listen.owner" = config.services.nginx.user; + "listen.group" = config.services.nginx.group; + "pm.max_children" = 5; + "pm.start_servers" = 2; + "pm.min_spare_servers" = 1; + "pm.max_spare_servers" = 3; + "pm.max_requests" = 500; + }; + phpEnv."PATH" = lib.makeBinPath [pkgs.php]; + }; +} diff --git a/dev-environment/default.nix b/dev-environment/default.nix index 8bd8d0bf..577986c1 100644 --- a/dev-environment/default.nix +++ b/dev-environment/default.nix @@ -19,7 +19,11 @@ # ./deprecated/php.nix ] ++ lib.optionals servicesSettings.adb [./adb-toolchain.nix] - ++ lib.optionals servicesSettings.nginx [./nginx.nix]; + ++ lib.optionals servicesSettings.nginx [ + ./nginx.nix + ./adminer.nix + ./mysql.nix + ]; programs.java.enable = true; } diff --git a/dev-environment/mysql.nix b/dev-environment/mysql.nix new file mode 100644 index 00000000..c4d4c7ff --- /dev/null +++ b/dev-environment/mysql.nix @@ -0,0 +1,11 @@ +# Import of thie module is controlled by bool: servicesSettings.nginx +{pkgs, ...}: { + # MySQL service, can be accessed by cli mariadb + # or a graphical frontend like adminer + services.mysql = { + enable = true; + package = pkgs.mariadb; + }; + # mycli is a MySQL cli helper with auto-completion and syntax highlighting + environment.systemPackages = with pkgs; [mycli]; +} diff --git a/dev-environment/nginx.nix b/dev-environment/nginx.nix index 3c97bb97..6aad6cdc 100644 --- a/dev-environment/nginx.nix +++ b/dev-environment/nginx.nix @@ -27,20 +27,11 @@ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; - include ${pkgs.nginx}/conf/fastcgi.conf; + include ${config.services.nginx.package}/conf/fastcgi.conf; ''; }; }; - # MySQL service, can be accessed by cli mariadb - # or a graphical frontend like adminer - services.mysql = { - enable = true; - package = pkgs.mariadb; - }; - # mycli is a MySQL cli helper with auto-completion and syntax highlighting - environment.systemPackages = with pkgs; [ mycli ]; - # PHP-FPM pool configuration # Needed for nginx to communicate with PHP services.phpfpm.pools.mypool = { diff --git a/home-manager/web-server-html/default.nix b/home-manager/web-server-html/default.nix index e4e29874..dcbc9bd2 100644 --- a/home-manager/web-server-html/default.nix +++ b/home-manager/web-server-html/default.nix @@ -12,16 +12,5 @@ "Website-Instances/index.php".source = ./index.php; "Website-Instances/logos/nginx-logo.png".source = ./logos/nginx-logo.png; "Website-Instances/logos/nixos-logo.png".source = ./logos/nixos-logo.png; - - # To use adminer, just type localhost/dbms/adminer.php in your browser - # This configuration automatically places the php file in the correct location - - # Adminer pematon (new version) with adminer theme - # After any changes we need to restart the services - # systemctl restart phpfpm-mypool.service nginx.service - "Website-Instances/adminer" = { - source = self.packages.${pkgs.system}.adminer-pematon-with-adminer-theme; - recursive = true; - }; }; } diff --git a/system/network.nix b/system/network.nix index 1a8bc24d..ee143a33 100644 --- a/system/network.nix +++ b/system/network.nix @@ -1,7 +1,20 @@ # Configure networking, firewall, proxy, etc. -{...}: { +{ + lib, + servicesSettings, + ... +}: { # Enable WIFI, Ethernet, ... networking.networkmanager.enable = true; + + networking.extraHosts = + lib.concatStringsSep "\n" + (lib.mapAttrsToList (name: ip: "${ip} ${name}") { + "adminer.local" = "127.0.0.1"; + # "myhost" = "127.0.0.1"; + # "myhost2" = "127.0.0.1"; + }); + /* networking.networkmanager.wifi.backend = "iwd"; # newer backend