Next, build the image using the Dockerfile in the project root (build for almalinux:9):
```
docker build -t nginx-mod_rewrite .
```
We obtain an image with nginx and the built mod_rewrite.
To run the image, you need to execute the command:
```
docker run --name nginx-mod_rewrite -p 8080:80 -p 8081:8081 nginx-mod_rewrite
```
## Building the package for a specified operating system
In the project root there is a script `package_preparer.sh` that allows you to build an rpm or deb package for a specific operating system. Which OS and native nginx version the package will be built for depends on the image used.
works correctly, the following utilities must be installed and available on the system (each of which comes from a package supplied by your Linux distribution):
| Utility | What it does in the `prepare` section | Package (Debian/Ubuntu) |
| **`docker`** (commands `docker build`, `docker run`, `docker rmi`) | Builds a temporary image, runs a container, cleans up | `docker.io` / `docker-ce` + running **daemon** |
> **Note on `sed`**
> The script uses extended regular expressions (`sed -E`) and in-place file modification (`sed -i`). This is the GNU variant of `sed`. On systems where `sed` is the BSD variant (e.g., macOS), the command `sed -E -i` will not work, so in such environments you need to install GNU `sed` (`gsed`) and replace calls with `gsed`.
The Docker daemon must be running, and the user must have permission to use it (or be in the `docker` group).
The main build occurs in a Docker container, so the base system does not get cluttered with extra packages. The set of utilities used by the script is present in the distribution by default, so you only need to install Docker.
The builder analyzes the nginx version installed in the distribution and performs the build in an environment with source files of the same nginx version, using commands similar to those used when building nginx from the distribution.
## Manual build from sources
If you need to build the module yourself, you need to run the following commands.
Here is an example for AlmaLinux 9.
Install the necessary build packages:
```
dnf -y install openssl-devel pcre-devel zlib-devel gcc gcc-c++ make wget
```
In the project root:
```
bash package_preparer.sh download 1.22.1
```
You can specify any available version on the website `https://nginx.org/ru/download.html`; it will be downloaded and extracted into the current directory.
Then change directory into nginx-1.22.1:
```
cd nginx-1.22.1
```
and set the build configuration. Here is an example configuration, it may differ; this example is a typical configuration: