> For the complete documentation index, see [llms.txt](https://documentation.ocsinventory-ng.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.ocsinventory-ng.org/administrator-docs/server-setup/security/securing-ocs-with-ssl.md).

# Securing OCS with SSL

OCS does not handle TLS itself. A reverse proxy in front of each component (**Nginx** for the back-end and the front-end) terminates the TLS connection on port **443** and forwards the request locally to the application. Enabling HTTPS therefore means:

1. obtaining a certificate (a public certificate + a private key);
2. provisioning the proxy to listen on `443` with those files;
3. pointing every `config.json` to the `https://` URL.

### Prerequisites

* A resolvable **domain name** (DNS A record) pointing to the server. A self-signed certificate works without a public domain.
* Ports **80** and **443** open on the server.
* A TLS certificate. OCS does not generate it, you must provide the following files, obtained from a Certificate Authority (CA) or self-signed:

| File                                            | Role                                                             | Nginx directive           |
| ----------------------------------------------- | ---------------------------------------------------------------- | ------------------------- |
| Private key (e.g. `<your-domain>.key`)          | Secret key, generated on the server, never shared                | `ssl_certificate_key`     |
| Server certificate (e.g. `<your-domain>.crt`)   | Your certificate, signed for your domain(s)                      | `ssl_certificate`         |
| CA chain / bundle (e.g. `<your-domain>-ca.crt`) | Intermediate (+ root) certificates of the issuing CA if provided | `ssl_trusted_certificate` |

A CA-signed certificate is obtained by generating a private key and a **CSR** (Certificate Signing Request) on the server, submitting the CSR to your **CA**, and installing the certificate it returns (with its CA chain). The private key never leaves the server. Generating these files is outside the scope of this documentation refer to your CA's instructions.

***

### Back-end

Start from the shipped config and apply **only** these changes.

#### Packages

In `/etc/nginx/sites-enabled/ocsinventory-backend`:

```nginx
server {
    listen 80;
    server_name <your-domain>;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name <your-domain>;

    ssl_certificate     /etc/ssl/certs/<your-domain>.crt;   #    add
    ssl_certificate_key /etc/ssl/private/<your-domain>.key;     #    add
    ssl_trusted_certificate /etc/ssl/certs/<your-domain>-ca.crt;   # add (CA chain, if provided)

    # ...
}
```

```bash
sudo nginx -t && sudo systemctl reload nginx
```

#### Docker

Mount the certificates into the proxy (port `443` is already exposed):

```yaml
  ocsinventory-proxy:
    volumes:
      # ... 
      - /etc/ssl:/etc/ssl:ro   # add
```

Then apply the same `listen 443 ssl;` + `ssl_certificate*` changes inside `files/nginx/ocsinventory-backend.conf`, and `docker compose up -d`.

***

### Front-end

In the frontend site config:

```nginx
server {
    listen 80;
    server_name <your-domain>;
    return 301 https://$host$request_uri;   # redirect to HTTPS
}

server {
    listen 443 ssl;             # was: listen 80;
    server_name <your-domain>;

    ssl_certificate     /etc/ssl/certs/<your-domain>.crt;   # add
    ssl_certificate_key /etc/ssl/private/<your-domain>.key;     # add
    ssl_trusted_certificate /etc/ssl/certs/<your-domain>-ca.crt;   # add (CA chain, if provided)

    # ...
}
```

```bash
sudo nginx -t && sudo systemctl reload nginx
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://documentation.ocsinventory-ng.org/administrator-docs/server-setup/security/securing-ocs-with-ssl.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
