Nginx: compile

  

(33条消息) nginx 交叉编译 ( 上 )_爱唠叨的老鱼的博客-CSDN博客_nginx 交叉编译

 添加VIM语法支持: 

cp --no-dereference -r --preserve=all contrib/vim/* ~/.vim

 

 

 

 

 

查看man: 

man man/nginx.8

 

 

 

 

 

 

  1. install prerequisites
    yum install zlib-devel pcre-devel geoip-devel openssl-devel libxml2-devel libxslt-devel gd-devel 

     

  2. compile arguments
    复制代码
    ./configure \
    --user=nginx \
    --group=nginx \
    --build=build_name \
    --prefix=/usr/local/nginx \
    --sbin-path=/usr/local/nginx/sbin/nginx \
    --conf-path=/usr/local/nginx/conf/nginx.conf \
    --error-log-path=/usr/local/nginx/logs/error.log \
    --http-log-path=/usr/local/nginx/logs/access.log \
    --pid-path=/usr/local/nginx/logs/nginx.pid \
    --lock-path=/usr/local/nginx/logs/nginx.lock \
    --modules-path=/usr/local/nginx/modules \
    --http-client-body-temp-path=/var/cache/nginx/client_temp \
    --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
    --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
    --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
    --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
    --with-compat \
    --with-file-aio \
    --with-threads \
    --with-pcre-jit \
    --with-http_addition_module \
    --with-http_auth_request_module \
    --with-http_dav_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_image_filter_module=dynamic \
    --with-http_random_index_module \
    --with-http_realip_module \
    --with-http_secure_link_module \
    --with-http_slice_module \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-http_sub_module \
    --with-http_v2_module \
    --with-http_xslt_module=dynamic \
    --with-http_geoip_module=dynamic \
    --with-mail \
    --with-mail_ssl_module \
    --with-stream \
    --with-stream_realip_module \
    --with-stream_ssl_module \
    --with-stream_ssl_preread_module \
    --with-debug \
    --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' \
    --add-dynamic-module=/root/headers-more-nginx-module-0.33 \
    --add-dynamic-module=/root/nginx_cookie_flag_module-1.1.0 \
    --add-dynamic-module=/root/njs-0.6.2/nginx
    复制代码

     

  3. Sysv service script
    复制代码
    #!/bin/env bash
    # description: Nginx Service Script
    exe=/usr/local/nginx/sbin/nginx
    pid=/usr/local/nginx/logs/nginx.pid
    conf=/usr/local/nginx/conf/nginx.conf
    
    case "$1" in
      start)
        if [ -f $pid ];then
          echo "nginx is running ..."
          exit 1
        else
          echo "nginx is starting ..."
          $exe -c $conf
        fi
        ;;
      stop)
        if [ -f $pid ];then
          echo "nginx is stopping ..."
          kill -SIGTERM "$(/bin/cat $pid)"
          rm -f $pid
        else
          echo "nginx is not running!"
          exit 2
        fi
        ;;
      restart)
        if $0 stop;then
          sleep 2
        fi
        $0 start
        ;;
      try-restart)
        if [ ! -f $pid ];then
          echo "nginx is not runing!"
          exit 11
        fi
        $0 restart
        ;;
      reload)
        if [ -f $pid ];then
          echo "nginx is reloading ..."
          kill -SIGHUP "$(/bin/cat $pid)"
        else
          echo "nginx is not running!"
          exit 3
        fi
        ;;
      status)
        if [ -f $pid ];then
          echo "nginx is running!"
        else
          echo "nginx stopped!"
        fi
        ;;
      *)
        echo "Usage: $0 (start | stop | restart | try-restart | reload | status)"
        exit 4
        ;;
    esac
    复制代码

     

  4. systemd unit
    复制代码
    [Unit]
    Description=nginx - high performance web server
    Documentation=http://nginx.org/en/docs/
    After=network-online.target remote-fs.target nss-lookup.target
    Wants=network-online.target
    
    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
    #ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"
    #ExecStop=/usr/local/nginx/sbin/nginx -s quit
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    复制代码


    /etc/systemd/system/nginx.service.d/override.conf

    [Service]
    ExecStart=
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

     

  5. signal
    killall -SIGHUP nginx  # reload
    killall -SIGQUIT nginx  # stop
    killall -SIGUSR1 nginx  # reopen log files
    killall -SIGUSR2 nginx  # 平滑升级

     

  6. njs
    复制代码
    cd /usr/local/nginx
    mkdir -p js
    
    cat > js/agitation.js <<EOF
    function hello(){
        return(201, 'Hello agitation')
    }
    
    export default {
        hello
    }
    EOF
    
    # nginx.conf
    load_module modules/ngx_http_js_module.so;
    
    http {
      js_import js/agitation.js;
      location /js {
        add_header content-type 'text/html; charset=utf-8';
        js_content agitation.hello;
      }
    }
    复制代码

     官方文档
    http://nginx.org/en/docs/njs/index.html

posted @   ascertain  阅读(53)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2020-10-19 openswan IPSec
点击右上角即可分享
微信分享提示