Redirect a port to roundcube

Hello i’m selfhosting a nixos server.

I have some issue to redirect port to my roundcube. I use ngnix to redirect to vaultgarden too

Currently i have for roundcube, and

{ config,pkgs, ... }:

{
  services.roundcube = {
    enable = true;
    hostName = "${config.HostName}";

    plugins = [ "multiple_accounts" ];

    configureNginx = false;

    extraConfig = ''
      # PurelyMail is the entreprise who host my mail
      $config['default_host'] = 'ssl://imap.purelymail.com';
      $config['default_port'] = 993;
      $config['smtp_server'] = 'tls://smtp.purelymail.com';
      $config['smtp_port'] = 465;
      $config['smtp_user'] = '%u';
      $config['smtp_pass'] = '%p';
    '';
  };

  services.nginx = {
    virtualHosts."${config.HostName}" = {
      listen = [
        { addr = "0.0.0.0"; port = 1984; }
      ];
    };
  };

  networking.firewall.allowedTCPPorts = [ 1984 ];

}

for vaultwarden

{ config, pkgs, ... }:

{
  services.vaultwarden = {
    enable = true;

    backupDir = "/var/local/vaultwarden/backup";

    config = {
      SIGNUPS_ALLOWED = true;
      ROCKET_PORT = 8222;
    };
  };

  services.nginx = {
    enable = true;

    virtualHosts = {
      "${config.HostName}" = {
        listen = [{ addr = "0.0.0.0"; port = 8000; }];
        locations."/" = {
          proxyPass = "http://127.0.0.1:8222";
          extraConfig = ''
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
          '';
        };
      };
    };
  };

  networking.firewall.allowedTCPPorts = [ 8000 ];
}

But both port redirect to vaulwarden, i want 1984 to go to roundcube and 8000 to go to vaulwarden

fix it, here ma solution

services.nginx = {
    enable = true;
    virtualHosts = {
      "${config.HostName}-vault" = {
        listen = [
          { addr = "0.0.0.0"; port = 8000; }
        ];

        locations."/" = {
          proxyPass = "http://127.0.0.1:8222";
          extraConfig = ''
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
          '';
        };
      };

      "${config.HostName}-roundcube" = {
        listen = [
          { addr = "0.0.0.0"; port = 1984; }
        ];

        root = "${pkgs.roundcube}/public_html";

        locations."/" = {
          extraConfig = ''
            index index.php index.html;
            try_files $uri $uri/ /index.php?$args;
          '';
        };

        locations."~ \\.php$" = {
          extraConfig = ''
            include ${pkgs.nginx}/conf/fastcgi_params;
            fastcgi_pass unix:/run/phpfpm/roundcube.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          '';
        };
      };
    };
  };

I use the socket that roundcube provide

1 Like