> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/it/configurazione/overleaf-toolkit/tls-proxy.md).

# Proxy TLS

Un proxy TLS opzionale per terminare le connessioni HTTPS, usando NGINX.

Esegui `bin/init --tls` per inizializzare la configurazione locale con la configurazione del proxy NGINX, oppure per aggiungere la configurazione del proxy NGINX a una configurazione locale esistente. Una **di esempio** chiave privata viene creata in `config/nginx/certs/overleaf_key.pem` e un **fittizio** certificato in `config/nginx/certs/overleaf_certificate.pem`. Oppure sostituiscili con la tua chiave privata e il tuo certificato reali, oppure imposta i valori di `TLS_PRIVATE_KEY_PATH` e `TLS_CERTIFICATE_PATH` alle rispettive posizioni della tua chiave privata e del tuo certificato reali.

Una configurazione predefinita per NGINX è fornita in `config/nginx/nginx.conf` che può essere personalizzata in base alle tue esigenze. Il percorso del file di configurazione può essere modificato con la `NGINX_CONFIG_PATH` variabile.

{% hint style="success" %}
Se hai un **docker-compose.yml** basato su, oppure gestisci il tuo proxy inverso NGINX, puoi vedere un esempio **nginx.conf** file [qui](https://github.com/overleaf/toolkit/blob/master/lib/config-seed/nginx.conf).
{% endhint %}

Aggiungi la seguente sezione al tuo `config/overleaf.rc` file, se non è già presente:

```
# Configurazione del proxy TLS (opzionale)
NGINX_ENABLED=false
NGINX_CONFIG_PATH=config/nginx/nginx.conf
NGINX_HTTP_PORT=80

# Sostituisci questi indirizzi IP con l'indirizzo IP esterno del tuo host
NGINX_HTTP_LISTEN_IP=127.0.1.1 
NGINX_TLS_LISTEN_IP=127.0.1.1
TLS_PRIVATE_KEY_PATH=config/nginx/certs/overleaf_key.pem
TLS_CERTIFICATE_PATH=config/nginx/certs/overleaf_certificate.pem
TLS_PORT=443
```

{% hint style="danger" %}
Se stai utilizzando un proxy TLS esterno (cioè non gestito dal toolkit Overleaf), assicurati che `OVERLEAF_TRUSTED_PROXY_IPS=loopback,<ip-of-your-tls-proxy>` sia impostato nel tuo `config/variables.env`, ad esempio `OVERLEAF_TRUSTED_PROXY_IPS=loopback,192.168.13.37`.
{% endhint %}

{% hint style="danger" %}
Se stai utilizzando una subnet di `172.16.0.0/12` (sottorete predefinita per le reti Docker) per la tua rete locale, dovrai impostare `OVERLEAF_TRUSTED_PROXY_IPS=loopback,<network>` nel tuo `config/variables.env`. Dove `<network>` è il `valore IPAM -> Config -> Subnet` in `docker inspect overleaf_default`, ad esempio `OVERLEAF_TRUSTED_PROXY_IPS=loopback,172.19.0.0/16`. Questo serve a prevenire la contraffazione delle `intestazioni X-Forwarded` .
{% endhint %}

{% hint style="info" %}
Se `OVERLEAF_TRUSTED_PROXY_IPS` non è impostato manualmente, il valore predefinito è `loopback`. Se lo imposti manualmente, devi assicurarti di includere uno di `loopback`, `localhost` o `127.0.0.1`, che considera affidabile l' **nginx** istanza in esecuzione all'interno del **contenitore sharelatex** contenitore.
{% endhint %}

Se hai configurato correttamente gli IP del proxy attendibile, dovresti vedere il tuo indirizzo IP pubblico nella `/user/sessions` pagina in questo modo:

<figure><img src="/files/ca098cbd17ab99810ab0eb770b847a32e188d015" alt="" width="375"><figcaption></figcaption></figure>

Se l'indirizzo IP mostrato sopra è ancora qualcosa come `127.0.0.1` o un indirizzo IP di rete privata/locale, controlla la configurazione del tuo proxy attendibile, in particolare il valore di `OVERLEAF_TRUSTED_PROXY_IPS`.

Per eseguire il proxy, cambia il valore di `NGINX_ENABLED` variabile in `config/overleaf.rc` da `false` a `true` e riesegui `bin/up`.

Per impostazione predefinita, l'interfaccia web HTTPS sarà disponibile su `https://127.0.1.1:443`. Le connessioni a `http://127.0.1.1:80` verranno reindirizzate a `https://127.0.1.1:443`. Per modificare l'indirizzo IP su cui NGINX è in ascolto, imposta le `NGINX_HTTP_LISTEN_IP` e `NGINX_TLS_LISTEN_IP` variabili. Le porte possono essere modificate tramite le `NGINX_HTTP_PORT` e `TLS_PORT` variabili.

Se NGINX non riesce ad avviarsi con il messaggio di errore `Error starting userland proxy: listen tcp4 ... bind: address already in use` assicurati che `OVERLEAF_LISTEN_IP:OVERLEAF_PORT` non si sovrapponga a `NGINX_HTTP_LISTEN_IP:NGINX_HTTP_PORT`.

```mermaid
sequenceDiagram
participant user as Utente
participant external as Host esterno
participant internal as Host interno
participant nginx as nginx
participant sharelatex as sharelatex
participant git-bridge as git-bridge
%% L'utente si connette all'host esterno HTTP
user->>+ external: HTTP
note over external: NGINX_HTTP_LISTEN_IP:NGINX_HTTP_PORT
external->>+ nginx: HTTP
note over nginx: nginx:80
nginx-->>-external: 301
%% L'utente si connette all'host esterno HTTPS
user->>+ external: HTTPS
note over external: NGINX_TLS_LISTEN_IP:TLS_PORT
external->>+ nginx: HTTPS
note over nginx: nginx:443
nginx->>+ sharelatex: HTTP
note over sharelatex: sharlatex:80
%% L'utente si connette a localhost HTTP
user->>+ internal: HTTP
note over internal: OVERLEAF_LISTEN_IP:OVERLEAF_PORT
internal->>+sharelatex: HTTP
note over sharelatex: sharlatex:80
%% sharelatex si connette a git-bridge
sharelatex->>+git-bridge: HTTP /git/
note over git-bridge: git-bridge:8000
note over sharelatex: GIT_BRIDGE_HOST:GIT_BRIDGE_PORT
git-bridge->>+sharelatex: WEB/WEB-API:3000
git-bridge->>+sharelatex: HISTORY-V1:3100
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/on-premises/it/configurazione/overleaf-toolkit/tls-proxy.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
