> 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/pt/configuracao/overleaf-toolkit/tls-proxy.md).

# Proxy TLS

Um proxy TLS opcional para terminar ligações HTTPS, usando NGINX.

Executar `bin/init --tls` para inicializar a configuração local com a configuração de proxy NGINX, ou para adicionar a configuração de proxy NGINX a uma configuração local existente. Um **de exemplo** chave privada é criada em `config/nginx/certs/overleaf_key.pem` e um **simulado** certificado em `config/nginx/certs/overleaf_certificate.pem`. Substitua-os pela sua verdadeira chave privada e pelo seu certificado, ou defina os valores das `TLS_PRIVATE_KEY_PATH` e `TLS_CERTIFICATE_PATH` variáveis para os caminhos da sua verdadeira chave privada e do seu certificado, respetivamente.

Uma configuração predefinida para o NGINX é fornecida em `config/nginx/nginx.conf` que pode ser personalizada de acordo com os seus requisitos. O caminho para o ficheiro de configuração pode ser alterado com a `NGINX_CONFIG_PATH` variável.

{% hint style="success" %}
Se tiver uma **docker-compose.yml** implementação baseada em, ou gerir o seu próprio proxy reverso NGINX, pode ver um exemplo **nginx.conf** ficheiro [aqui](https://github.com/overleaf/toolkit/blob/master/lib/config-seed/nginx.conf).
{% endhint %}

Adicione a seguinte secção ao seu `config/overleaf.rc` ficheiro, se ainda não existir:

```
# Configuração do proxy TLS (opcional)
NGINX_ENABLED=false
NGINX_CONFIG_PATH=config/nginx/nginx.conf
NGINX_HTTP_PORT=80

# Substitua estes endereços IP pelo endereço IP externo do seu anfitrião
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 estiver a utilizar um proxy TLS externo (ou seja, não gerido pelo Overleaf Toolkit), certifique-se de que `OVERLEAF_TRUSTED_PROXY_IPS=loopback,<ip-of-your-tls-proxy>` está definido no seu `config/variables.env`, por exemplo `OVERLEAF_TRUSTED_PROXY_IPS=loopback,192.168.13.37`.
{% endhint %}

{% hint style="danger" %}
Se estiver a utilizar uma sub-rede de `172.16.0.0/12` (sub-rede predefinida para redes Docker) para a sua rede local, terá de definir `OVERLEAF_TRUSTED_PROXY_IPS=loopback,<network>` no seu `config/variables.env`. Onde `<network>` é o `IPAM -> Config -> Subnet` valor em `docker inspect overleaf_default`, por exemplo `OVERLEAF_TRUSTED_PROXY_IPS=loopback,172.19.0.0/16`. Isto serve para evitar a falsificação dos `X-Forwarded` cabeçalhos.
{% endhint %}

{% hint style="info" %}
Se o `OVERLEAF_TRUSTED_PROXY_IPS` não estiver definido manualmente, o valor predefinido é `loopback`. Se definir manualmente, tem de se certificar de que inclui um de `loopback`, `localhost` ou `127.0.0.1`, que confia na **nginx** instância em execução dentro do **sharelatex** contentor.
{% endhint %}

Se tiver configurado corretamente os IPs do proxy de confiança, deverá ver o seu endereço IP público na página `/user/sessions` assim:

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

Se o endereço IP mostrado acima ainda for algo como `127.0.0.1` ou um endereço IP de rede privada/local, verifique a configuração do seu proxy de confiança, especialmente o valor de `OVERLEAF_TRUSTED_PROXY_IPS`.

Para executar o proxy, altere o valor da `NGINX_ENABLED` variável em `config/overleaf.rc` de `false` para `true` e volte a executar `bin/up`.

Por predefinição, a interface web HTTPS estará disponível em `https://127.0.1.1:443`. As ligações para `http://127.0.1.1:80` serão redirecionadas para `https://127.0.1.1:443`. Para alterar o endereço IP em que o NGINX escuta, defina as `NGINX_HTTP_LISTEN_IP` e `NGINX_TLS_LISTEN_IP` variáveis. As portas podem ser alteradas através das `NGINX_HTTP_PORT` e `TLS_PORT` variáveis.

Se o NGINX falhar ao iniciar com a mensagem de erro `Error starting userland proxy: listen tcp4 ... bind: address already in use` certifique-se de que `OVERLEAF_LISTEN_IP:OVERLEAF_PORT` não se sobrepõe a `NGINX_HTTP_LISTEN_IP:NGINX_HTTP_PORT`.

```mermaid
sequenceDiagram
participant user as Utilizador
participant external as Anfitrião externo
participant internal as Anfitrião interno
participant nginx as nginx
participant sharelatex as sharelatex
participant git-bridge as git-bridge
%% O utilizador liga-se ao anfitrião externo por 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
%% O utilizador liga-se ao anfitrião externo por 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
%% O utilizador liga-se ao localhost por HTTP
user->>+ internal: HTTP
note over internal: OVERLEAF_LISTEN_IP:OVERLEAF_PORT
internal->>+sharelatex: HTTP
note over sharelatex: sharlatex:80
%% O sharelatex liga-se ao 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/pt/configuracao/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.
