Nginx SSH Memo
Enable Nginx
On the server:
services.nginx = {
enable = true;
virtualHosts = {
"example.com" = {
listen = [
{ addr = "0.0.0.0"; port = 8080; }
];
locations."/".proxyPass = "http://localhost:8000";
};
};
};
SSH tunnel
On the client:
ssh username@host -L 8999:host:8080
Then access to http://127.0.0.1:8999/ from the client
Allow TCP Forwarding
On the server:
networking.firewall.allowedTCPPorts = [ 8080 ];
Now the service on port 8000 on the server should be accessible from http://ip_address:8080/
Keep the port 80
If we want to use 80, Nginx is listening to the port 80 by default so:
services.nginx = {
enable = true;
virtualHosts = {
"example.com" = {
locations."/".proxyPass = "http://localhost:8000";
};
};
};
networking.firewall.allowedTCPPorts = [ 80 ];
Then go to http://192.168.x.x/