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

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

Motivation

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

Evnironment

  • Ubuntu 22.04

Procedure

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

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

    1
    2
    3
    4
    5
    6
    
    wget github.com/PCRE2Project/pcre2/releases/download/pcre2-10.42/pcre2-10.42.tar.gz
    tar -zxf pcre2-10.42.tar.gz
    cd pcre2-10.42
    ./configure
    make
    sudo make install
    
  3. 安裝 zlib (依照自身需求修改版本號)

    1
    2
    3
    4
    5
    6
    
    wget http://zlib.net/zlib-1.2.13.tar.gz
    tar -zxf zlib-1.2.13.tar.gz
    cd zlib-1.2.13
    ./configure
    make
    sudo make install
    
  4. 安裝 nginx (依照自身需求修改版本號)

    1
    2
    3
    
    wget https://nginx.org/download/nginx-1.24.0.tar.gz
    tar zxf nginx-1.24.0.tar.gz
    cd nginx-1.24.0
    
  5. 設定模組 (以下指令必須為單行)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
    ./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. 編譯並安裝

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

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

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

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

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

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    
    [Unit]
    Description=Nginx - high performance web server
    Documentation=http://nginx.org/en/docs/
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s quit
    ExecStartPost=/bin/sleep 0.1
    PIDFile=/usr/local/nginx/logs/nginx.pid
    
    [Install]
    WantedBy=multi-user.target
    
  12. Reload systemd

    1
    
    sudo systemctl daemon-reload
    
  13. 啟動 Nginx

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

    1
    
    sudo systemctl status nginx
    

Reference

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus