Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$has_disclaimer is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_lock is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_meta_box_present is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_send_notification is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_modify_title_and_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_heading is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_category is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_blz_affiliation_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_content_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_speciali is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskw is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_linkdex is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_content_score is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskeywords is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_keywordsynonyms is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_estimated-reading-time-minutes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_wordproof_timestamp is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$response_body is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_indexnow_last_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
ngrok: come esporre un server locale su Internet | IlSoftware.it

ngrok: come esporre un server locale su Internet

Cos'è ngrok e come funziona il servizio che permette di esporre sulla rete Internet qualunque servizio in esecuzione in locale, senza preoccuparsi del NAT, del firewall e in generale della configurazione di rete.

Vi sarà certamente capitato di voler esporre uno o più servizi sulla rete Internet in modo da renderli accessibili da remoto. Supponete di essere al lavoro su un progetto in ambito locale ma avete la necessità di mostrarlo a un gruppo di utenti che si collegano a distanza. Per esporre un server locale su Internet sono di norma necessari diversi passaggi. ngrok spazza via tutte le possibili complicazioni.

L’approccio classico consiste nell’annotare il numeri di porta sul quale il server locale si è posto in ascolto quindi attivare il port forwarding sul router. Il sistema sul quale è in esecuzione il modulo server dovrebbe aver un indirizzo IP privato statico e il router, grazie al port forwarding, vi inoltrerà tutto il traffico ricevuto sull’indirizzo IP pubblico (esclusivamente sulla porta in ingresso indicata).

Ci sono però situazioni in cui superare il NAT (Network Address Translation) impostato dal router locale non basta. Tanti provider, infatti, non mettono più a disposizione un indirizzo IP pubblico (neppure dinamico) al singolo utente: lo stesso IP è condiviso tra più abbonati dell’operatore di telecomunicazioni. Ne parliamo nell’articolo su CGNAT e MAP-T.

Eliminare tutte le complicazioni con ngrok

ngrok è uno strumento potente e versatile utilizzato dagli sviluppatori per esporre server locali dietro NAT e firewall. È particolarmente utile per testare e sviluppare applicazioni Web, consentendo un accesso sicuro e temporaneo ai server locali, senza dover apportare modifiche sulla configurazione di rete o aprire porte specifiche.

Il servizio funziona creando un tunnel sicuro tra il server locale e un sistema remoto, cui è associato un indirizzo pubblico di tipo mnemonico. Di fatto, ngrok è un reverse proxy server multipiattaforma (è disponibile nelle versoni per Linux, macOS e Windows).

Schema funzionamento ngrok

L’immagine raffigura i possibili campi applicativi di ngrok ed è tratta dalla pagina “Use cases“.

Come installare e usare ngrok

Sul sito ufficiale di ngrok, sono disponibili le istruzioni per l’installazione. Con le distribuzioni Linux che supportano la gestione dei pacchetti con Snap, è sufficiente aprire la finestra del terminale e digitare quanto segue per avviare l’installazione di ngrok:

snap install ngrok

Dopo l’installazione, è possibile autenticarsi creando un account su ngrok. Si ottiene così un token personale che permette di accedere a tutta una serie di funzionalità avanzate. Sempre dalla finestra del terminale Linux, basta digitare ngrok config add-authtoken seguito dal lungo token alfanumerico ottenuto consultando la propria area privata sul sito del progetto ngrok.

Supponendo di aver avviato un server locale che apre la porta 3000, essa non sarà raggiungibile per via del NAT e del firewall in esecuzione sul router. Digitando semplicemente il comando che segue, ngrok fornisce un indirizzo IP mnemonico che consente di raggiungere da remoto il servizio in ascolto sulla porta indicata, indipendentemente dalla configurazione della rete e dei dispositivi:

ngrok http 3000

Al posto di 3000, deve ovviamente essere indicato il numero della porta di comunicazione sulla quale il server locale è in ascolto.

L’URL pubblico HTTPS generato da ngrok

In risposta alla richiesta dell’utente, ngrok genera automaticamente un URL pubblico ovvero un indirizzo del tipo ngrok-free.app o similare che reindirizza tutto il traffico in ingresso verso il server locale. L’indirizzo mnemonico visualizzato da ngrok di solito inizia con un prefisso alfanumerico; si prosegue poi con un riferimento esplicito all’IP pubblico dell’utente; si chiude con il nome di dominio. Per maggiori informazioni, suggeriamo di fare riferimento alla struttura degli URL.

ngrok, accedere remoto server locale proxy

A qualunque utente remoto che debba collegarsi con il server locale, basta consegnare l’URL fornito da ngrok in corrispondenza della voce Forwarding. Tale indirizzo è anche cliccabile; inoltre, premendo il tasto destro e selezionando Copia collegamento, è possibile incollarlo con facilità in un’email, in un applicazione di messaggistica istantanea e così via.

Condivisione URL pubblico ngrok

Per interrompere la condivisione dell’accesso a distanza, su Linux basta ricorrere alla combinazione di tasti CTRL+C.

Principali vantaggi di ngrok

Un servizio come ngrok, che ha alcune limitazioni nel piano free ma che risultano in molti casi accettabili (20.000 richieste al mese gestibili come valore massimo), offre numerosi vantaggi che lo rendono uno strumento indispensabile per molti sviluppatori.

Come abbiamo visto, non richiede configurazioni complesse del router o del firewall, fornisce tunnel sicuri utilizzando HTTPS, mette a disposizione una comoda dashboard Web che permette di ispezionare le richieste HTTP in tempo reale, rendendo il debugging più semplice.

Il servizio, inoltre, permette di testare applicazioni da dispositivi remoti, senza doverle distribuire pubblicamente. Inoltre, facilita lo sviluppo e il test di Webhook, rendendo più semplice l’integrazione con servizi esterni.

ngrok dispone anche di molteplici funzionalità avanzate che possono essere sbloccate, spesso, sottoscrivendo un piano a pagamento. Si possono ad esempio creare e utilizzare sottodomini personalizzati, esporre altri tipi di servizi non basati su HTTP e configurare tunnel persistenti (evitano di generare un nuovo URL ogni volta che si avvia ngrok).

L’immagine in apertura è tratta dal sito ufficiale di ngrok.

Ti consigliamo anche

Link copiato negli appunti