Nginx / 2 min read

Build From Source - mail, http2, http3, stream modules

Build From Source with mail, http2, http3, stream modules

On this page

Motivation

  • 想要自己編譯 Nginx,並且加入一些模組
  • 新開了一個 Mail Server,想要使用 Nginx 作為 Mail Proxy Server

Evnironment

  • Ubuntu 22.04

Procedure

  1. 安裝編譯 Nginx 所需的套件

    Code
    sudo apt update
    sudo apt install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
  2. 安裝 PCRE (依照自身需求修改版本號)

    Code
    wget github.com/PCRE2Project/pcre2/releases/download/pcre2-10.42/pcre2-10.42.tar.gztar -zxf pcre2-10.42.tar.gzcd pcre2-10.42./configuremakesudo make install
  3. 安裝 zlib (依照自身需求修改版本號)

    Code
    wget http://zlib.net/zlib-1.2.13.tar.gztar -zxf zlib-1.2.13.tar.gzcd zlib-1.2.13./configuremakesudo make install
  4. 安裝 nginx (依照自身需求修改版本號)

    Code
    wget https://nginx.org/download/nginx-1.24.0.tar.gztar zxf nginx-1.24.0.tar.gzcd nginx-1.24.0
  5. 設定模組 (以下指令必須為單行)

    Code
    ./configure \    --with-pcre=../pcre2-10.42 \    --with-zlib=../zlib-1.3.1 \    --with-http_ssl_module \    --with-mail \    --with-mail_ssl_module \    --with-stream \    --with-stream_ssl_module \    --with-http_v2_module \    --with-http_v3_module
  6. 編譯並安裝

    Code
    makesudo make install
  7. 安裝完成的 Nginx 位於 /usr/local/nginx/,設定檔位於 /usr/local/nginx/conf/nginx.conf

  8. Nginx 執行檔位於 /usr/local/nginx/sbin/nginx,啟動 Nginx

    Code
    sudo /usr/local/nginx/sbin/nginx
  9. 把 Nginx 執行檔加入系統路徑

    Code
    sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
  10. 設定 Nginx 服務

    Code
    sudo vim /etc/systemd/system/nginx.service
  11. nginx.service 內容

    Code
    [Unit]Description=Nginx - high performance web serverDocumentation=http://nginx.org/en/docs/After=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s quitExecStartPost=/bin/sleep 0.1PIDFile=/usr/local/nginx/logs/nginx.pid[Install]WantedBy=multi-user.target
  12. Reload systemd

    Code
    sudo systemctl daemon-reload
  13. 啟動 Nginx

    Code
    sudo systemctl start nginx
  14. 查看 Nginx 狀態

    Code
    sudo systemctl status nginx

Reference

Discussion

留言會在接近此區域時載入。