Basic Setup for PHP Router

Hello everyone,

I would like to transfer my PHP project with the phprouter GitHub - phprouter/main: Secure router with XSS and CSRF to my new nixos server.

It works on any normal webspace with nginx. What does a “standard” nginx configuration look like?
When I start the server I get a 403 error on the website.

Unfortunately I could not find the right solution in the forum…sry

Can you help?

    virtualHosts."xxx.de" = {
      enableACME = true;  

      forceSSL = true; 
      root = "/var/www/xxx.de";
        locations."~* \.(js|css|svg|png|jpg|jpeg|gif|ico|ttf|webp|pdf|woff|woff2)$" = {
          extraConfig = ''
            try_files $uri @rewrite;
            expires max;
            log_not_found off;
          '';
        };
        locations."/" = {
          extraConfig = ''
            access_log off;
            charset utf-8;
            etag off;
            index index.php;
              
            location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass  unix:${config.services.phpfpm.pools.xxxpool.socket};
                include ${pkgs.nginx}/conf/fastcgi_params;
                include ${pkgs.nginx}/conf/fastcgi.conf;
            }
          '';
        };
    };

  services.phpfpm.pools.xxxpool = {
    user = "nginx";
    phpOptions = ''
      upload_max_filesize = 512M
      post_max_size = 512M
      memory_limit = 512M
      '';	
      settings = {
        "listen.owner" = "nginx";
        "pm" = "dynamic";
        "pm.max_children" = 32;
        "pm.max_requests" = 500;
        "pm.start_servers" = 2;
        "pm.min_spare_servers" = 2;
        "pm.max_spare_servers" = 5;
        "php_admin_value[error_log]" = "stderr";
        "php_admin_flag[log_errors]" = true;
        "catch_workers_output" = true;
      };
      phpEnv."PATH" = lib.makeBinPath [ pkgs.php ];
    };
1 Like