Skip to content

Commit

Permalink
nginx: configure adminer.local virtual host
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRTitor committed Nov 3, 2024
1 parent 1e9feeb commit cdbef8b
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 23 deletions.
60 changes: 60 additions & 0 deletions dev-environment/adminer.nix
Original file line number Diff line number Diff line change
@@ -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];
};
}
6 changes: 5 additions & 1 deletion dev-environment/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 11 additions & 0 deletions dev-environment/mysql.nix
Original file line number Diff line number Diff line change
@@ -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];
}
11 changes: 1 addition & 10 deletions dev-environment/nginx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
11 changes: 0 additions & 11 deletions home-manager/web-server-html/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
}
15 changes: 14 additions & 1 deletion system/network.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit cdbef8b

Please sign in to comment.