> 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/vi/cau-hinh/overleaf-toolkit/tls-proxy.md).

# Proxy TLS

Một proxy TLS tùy chọn để kết thúc các kết nối HTTPS, sử dụng NGINX.

Chạy `bin/init --tls` để khởi tạo cấu hình cục bộ với cấu hình proxy NGINX, hoặc để thêm cấu hình proxy NGINX vào một cấu hình cục bộ hiện có. Một **mẫu** khóa riêng được tạo trong `config/nginx/certs/overleaf_key.pem` và một **giả** chứng chỉ trong `config/nginx/certs/overleaf_certificate.pem`. Hoặc thay chúng bằng khóa riêng và chứng chỉ thực của bạn, hoặc đặt giá trị của các `TLS_PRIVATE_KEY_PATH` và `TLS_CERTIFICATE_PATH` thành các đường dẫn tới khóa riêng và chứng chỉ thực của bạn tương ứng.

Một cấu hình mặc định cho NGINX được cung cấp trong `config/nginx/nginx.conf` có thể được tùy chỉnh theo yêu cầu của bạn. Đường dẫn tới tệp cấu hình có thể được thay đổi bằng `NGINX_CONFIG_PATH` biến.

{% hint style="success" %}
Nếu bạn có một **docker-compose.yml** triển khai dựa trên, hoặc tự quản lý proxy ngược NGINX của riêng bạn, bạn có thể xem một ví dụ **nginx.conf** tệp [tại đây](https://github.com/overleaf/toolkit/blob/master/lib/config-seed/nginx.conf).
{% endhint %}

Thêm phần sau vào `config/overleaf.rc` tệp của bạn nếu nó chưa có sẵn:

```
# Cấu hình proxy TLS (tùy chọn)
NGINX_ENABLED=false
NGINX_CONFIG_PATH=config/nginx/nginx.conf
NGINX_HTTP_PORT=80

# Thay các địa chỉ IP này bằng địa chỉ IP bên ngoài của máy chủ của bạn
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" %}
Nếu bạn đang sử dụng một proxy TLS bên ngoài (tức là không được Overleaf Toolkit quản lý), vui lòng đảm bảo rằng `OVERLEAF_TRUSTED_PROXY_IPS=loopback,<ip-of-your-tls-proxy>` được đặt trong `config/variables.env`, ví dụ `OVERLEAF_TRUSTED_PROXY_IPS=loopback,192.168.13.37`.
{% endhint %}

{% hint style="danger" %}
Nếu bạn đang sử dụng một subnet từ `172.16.0.0/12` (subnet mặc định cho các mạng Docker) cho mạng cục bộ của bạn, bạn sẽ cần đặt `OVERLEAF_TRUSTED_PROXY_IPS=loopback,<network>` trong `config/variables.env`. Trong đó `<network>` là `IPAM -> Config -> Subnet` giá trị trong `docker inspect overleaf_default`, ví dụ `OVERLEAF_TRUSTED_PROXY_IPS=loopback,172.19.0.0/16`. Điều này nhằm ngăn chặn việc giả mạo các `X-Forwarded` header.
{% endhint %}

{% hint style="info" %}
Nếu `OVERLEAF_TRUSTED_PROXY_IPS` không được đặt thủ công thì mặc định là `loopback`. Nếu đặt thủ công, bạn phải đảm bảo bao gồm một trong `loopback`, `localhost` hoặc `127.0.0.1`, thứ này tin cậy **nginx** phiên bản đang chạy bên trong **sharelatex** container.
{% endhint %}

Nếu bạn đã cấu hình đúng các IP proxy đáng tin cậy, bạn sẽ thấy địa chỉ IP công khai của mình trên `/user/sessions` trang như sau:

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

Nếu địa chỉ IP hiển thị ở trên vẫn là thứ gì đó như `127.0.0.1` hoặc là địa chỉ IP của mạng riêng/mạng cục bộ, vui lòng kiểm tra cấu hình proxy đáng tin cậy của bạn, đặc biệt là giá trị của `OVERLEAF_TRUSTED_PROXY_IPS`.

Để chạy proxy, hãy thay đổi giá trị của `NGINX_ENABLED` biến trong `config/overleaf.rc` false `false` thành `true` và chạy lại `bin/up`.

Theo mặc định, giao diện web HTTPS sẽ khả dụng tại `https://127.0.1.1:443`. Các kết nối tới `http://127.0.1.1:80` sẽ được chuyển hướng tới `https://127.0.1.1:443`. Để thay đổi địa chỉ IP mà NGINX lắng nghe, hãy đặt `NGINX_HTTP_LISTEN_IP` và `NGINX_TLS_LISTEN_IP` các biến. Các cổng có thể được thay đổi thông qua các `NGINX_HTTP_PORT` và `TLS_PORT` biến.

Nếu NGINX không khởi động được với thông báo lỗi `Error starting userland proxy: listen tcp4 ... bind: address already in use` hãy đảm bảo rằng `OVERLEAF_LISTEN_IP:OVERLEAF_PORT` không trùng với `NGINX_HTTP_LISTEN_IP:NGINX_HTTP_PORT`.

```mermaid
sequenceDiagram
participant user as Người dùng
participant external as Máy chủ bên ngoài
participant internal as Máy chủ nội bộ
participant nginx as nginx
participant sharelatex as sharelatex
participant git-bridge as git-bridge
%% Người dùng kết nối tới máy chủ ngoài qua 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
%% Người dùng kết nối tới máy chủ ngoài qua 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
%% Người dùng kết nối tới localhost qua HTTP
user->>+ internal: HTTP
note over internal: OVERLEAF_LISTEN_IP:OVERLEAF_PORT
internal->>+sharelatex: HTTP
note over sharelatex: sharlatex:80
%% sharelatex kết nối tới 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/vi/cau-hinh/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.
