Skip to content

Commit

Permalink
Fix Nginx server
Browse files Browse the repository at this point in the history
Signed-off-by: John Titor <[email protected]>
  • Loading branch information
JohnRTitor committed Oct 1, 2024
1 parent d6a66f9 commit b57a91a
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions dev-environment/nginx.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
{
config,
pkgs,
lib,
userSettings,
pkgs,
...
}: {
services.nginx = {
enable = true;
virtualHosts.localhost = {
locations."/wiki" = {
return = "200 '<html><body>It works<br><?php phpinfo();></body></html>'";
extraConfig = ''
default_type text/html;
'';
};
services.nginx.enable = true;

# Nginx virtual host configuration for localhost
services.nginx.virtualHosts."localhost" = {
root = "/var/www/phptest";
extraConfig = ''
index index.php;
'';

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.mypool.socket};
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include ${pkgs.nginx}/conf/fastcgi.conf;
'';
};
};

environment.systemPackages = [ pkgs.php ];
# MySQL service
services.mysql = {
enable = true;
package = pkgs.mariadb;
};

# PHP-FPM pool configuration
# Needed for nginx to communicate with PHP
services.phpfpm.pools.mypool = {
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 ];
};
}

0 comments on commit b57a91a

Please sign in to comment.