ssh-tunnel-over-nginx
Example:
# Install nginx with ssh-tunnel backend. - ssh-tunnel-over-nginx: hostname: dev.frkl.io ssh_port: 3333 server_admin: [email protected]
Description
Set up a self-hosted service similar to ngrok.
A Nginx web server (with valid Letsencrypt https certificate) proxies content from your local machine, after you established an ssh-tunnel. You can use your own domain name(s), all you need is a virtual server somewhere on the internet.
To connect to the service, use:
ssh -N -T -R <ssh_port>:localhost:<your_local_application_port> [server_user@]<server_domain>
Then, you (or anyone else) can connect with a browser on 'https://server_domain'.
Resources
Variables
Name | Type | Default | Description |
---|---|---|---|
|
string | -- | The server admin email (used for the Letsencrypt cert request). Required |
|
string | localhost | The domain name the webserver should listen on. |
|
integer | 3333 | The port nginx should connect to (on the server). |
Examples
Example 1
Install nginx with ssh-tunnel backend.
Code
- ssh-tunnel-over-nginx: hostname: dev.frkl.io ssh_port: 3333 server_admin: [email protected]
Description
Install and configure Nginx to serve a proxied service running on a local laptop or similar.
To connect the proxied service, the developer would issue (assuming the service runs on port 5000 locally):
ssh -N -T -R 3333:localhost:5000 [email protected]
To access, a user could then visit 'https://dev.frkl.io' in a browser.
Code
doc: short_help: Set up a sort of self-hosted ngrok service. help: | Set up a self-hosted service similar to ngrok. A Nginx web server (with valid Letsencrypt https certificate) proxies content from your local machine, after you established an ssh-tunnel. You can use your own domain name(s), all you need is a virtual server somewhere on the internet. To connect to the service, use: ssh -N -T -R <ssh_port>:localhost:<your_local_application_port> [server_user@]<server_domain> Then, you (or anyone else) can connect with a browser on 'https://server_domain'. examples: - title: Install nginx with ssh-tunnel backend. desc: | Install and configure Nginx to serve a proxied service running on a local laptop or similar. To connect the proxied service, the developer would issue (assuming the service runs on port 5000 locally): ssh -N -T -R 3333:localhost:5000 [email protected] To access, a user could then visit 'https://dev.frkl.io' in a browser. vars: hostname: dev.frkl.io ssh_port: 3333 server_admin: [email protected] references: "'Roll your own Ngrok...' blog post": https://jerrington.me/posts/2019-01-29-self-hosted-ngrok.html args: hostname: doc: short_help: The domain name the webserver should listen on. type: string required: false default: localhost ssh_port: doc: short_help: The port nginx should connect to (on the server). type: integer default: 3333 required: true server_admin: doc: short_help: The server admin email (used for the Letsencrypt cert request). type: string required: true cli: metavar: EMAIL access_log: doc: short_help: The access log. type: string required: false cli: metavar: PATH error_log: doc: short_help: The error log path and (optional) log level. references: - '[Nginx core documentation](http://nginx.org/en/docs/ngx_core_module.html#error_log)' type: string required: false cli: metavar: PATH frecklets: - nginx-server-block-file: path: '/etc/nginx/sites-enabled/{{:: hostname ::}}.ssh_port_{{:: ssh_port ::}}.https.conf' use_https: true server_admin: '{{:: server_admin ::}}' server_names: - '{{:: hostname ::}}' owner: root location_blocks: - location_match: / properties: | proxy_pass http://localhost:{{:: ssh_port ::}}/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_redirect off; - webserver-service: webserver: nginx letsencrypt_webroot: /var/www/html use_https: true letsencrypt_email: '{{:: server_admin ::}}' letsencrypt_domains: - '{{:: hostname ::}}'
frecklecute --community ssh-tunnel-over-nginx --help Usage: frecklecute ssh-tunnel-over-nginx [OPTIONS] Set up a self-hosted service similar to ngrok. A Nginx web server (with valid Letsencrypt https certificate) proxies content from your local machine, after you established an ssh-tunnel. You can use your own domain name(s), all you need is a virtual server somewhere on the internet. To connect to the service, use: ssh -N -T -R <ssh_port>:localhost:<your_local_application_port> [server_user@]<server_domain> Then, you (or anyone else) can connect with a browser on 'https://server_domain'. Options: --server-admin EMAIL The server admin email (used for the Letsencrypt cert request). [required] --hostname HOSTNAME The domain name the webserver should listen on. --ssh-port SSH_PORT The port nginx should connect to (on the server). --help Show this message and exit.
# -*- coding: utf-8 -*- # # module path: pycklets.ssh_tunnel_over_nginx.SshTunnelOverNginx # from dataclasses import dataclass from pyckles import AutoPycklet from typing import * # noqa @dataclass class SshTunnelOverNginx(AutoPycklet): """Set up a self-hosted service similar to ngrok. A Nginx web server (with valid Letsencrypt https certificate) proxies content from your local machine, after you established an ssh-tunnel. You can use your own domain name(s), all you need is a virtual server somewhere on the internet. To connect to the service, use: ssh -N -T -R <ssh_port>:localhost:<your_local_application_port> [server_user@]<server_domain> Then, you (or anyone else) can connect with a browser on 'https://server_domain'. Args: hostname: The domain name the webserver should listen on. server_admin: The server admin email (used for the Letsencrypt cert request). ssh_port: The port nginx should connect to (on the server). """ FRECKLET_ID = "ssh-tunnel-over-nginx" hostname: str = None server_admin: str = None ssh_port: int = None def __post_init__(self): super(SshTunnelOverNginx, self).__init__(var_names=["hostname", "server_admin", "ssh_port"]) frecklet_class = SshTunnelOverNginx
# -*- coding: utf-8 -*- # # module path: pycklets.ssh_tunnel_over_nginx.SshTunnelOverNginx # from pyckles import AutoPycklet class SshTunnelOverNginx(AutoPycklet): """Set up a self-hosted service similar to ngrok. A Nginx web server (with valid Letsencrypt https certificate) proxies content from your local machine, after you established an ssh-tunnel. You can use your own domain name(s), all you need is a virtual server somewhere on the internet. To connect to the service, use: ssh -N -T -R <ssh_port>:localhost:<your_local_application_port> [server_user@]<server_domain> Then, you (or anyone else) can connect with a browser on 'https://server_domain'. Args: hostname: The domain name the webserver should listen on. server_admin: The server admin email (used for the Letsencrypt cert request). ssh_port: The port nginx should connect to (on the server). """ FRECKLET_ID = "ssh-tunnel-over-nginx" def __init__(self, hostname="localhost", server_admin=None, ssh_port=3333): super(SshTunnelOverNginx, self).__init__(var_names=["hostname", "server_admin", "ssh_port"]) self._hostname = hostname self._server_admin = server_admin self._ssh_port = ssh_port @property def hostname(self): return self._hostname @hostname.setter def hostname(self, hostname): self._hostname = hostname @property def server_admin(self): return self._server_admin @server_admin.setter def server_admin(self, server_admin): self._server_admin = server_admin @property def ssh_port(self): return self._ssh_port @ssh_port.setter def ssh_port(self, ssh_port): self._ssh_port = ssh_port frecklet_class = SshTunnelOverNginx