根据官网 Building nginx from Sources 的描述,我们可以通过config命令从源码上构建自己的 nginx。这种方式对我而言显得复杂了,当然是使用 homebrew 来安装啦,它都配置好了。

    1. brew install nginx

    安装完毕后运行nginx -h可以查询帮助,nginx -V可以显示 nginx 版本及配置选项,我的配置选项如下

    • 下面配置选项的意思可以参考 Building nginx from Sources
    • 文件路径也要对比瞧瞧,以后遇到问题就根据配置的路径寻找
    • 官网的后面教程提到了 nginx.conf文件的位置,在我们的系统中,它在 /opt/homebrew/etc/nginx/nginx.conf,这类东西要灵活查找

      1. configure arguments: --prefix=/opt/homebrew/Cellar/nginx/1.21.5 --sbin-path=/opt/homebrew/Cellar/nginx/1.21.5/bin/nginx --with-cc-opt='-I/opt/homebrew/opt/pcre/include -I/opt/homebrew/opt/openssl@1.1/include' --with-ld-opt='-L/opt/homebrew/opt/pcre/lib -L/opt/homebrew/opt/openssl@1.1/lib' --conf-path=/opt/homebrew/etc/nginx/nginx.conf --pid-path=/opt/homebrew/var/run/nginx.pid --lock-path=/opt/homebrew/var/run/nginx.lock --http-client-body-temp-path=/opt/homebrew/var/run/nginx/client_body_temp --http-proxy-temp-path=/opt/homebrew/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/opt/homebrew/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/opt/homebrew/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/opt/homebrew/var/run/nginx/scgi_temp --http-log-path=/opt/homebrew/var/log/nginx/access.log --error-log-path=/opt/homebrew/var/log/nginx/error.log --with-compat --with-debug --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --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-ipv6 --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
    • 它都是一行,下面我换行了一下,看得清晰一点

      1. configure arguments:
      2. --prefix=/opt/homebrew/Cellar/nginx/1.21.5
      3. --sbin-path=/opt/homebrew/Cellar/nginx/1.21.5/bin/nginx
      4. --with-cc-opt='-I/opt/homebrew/opt/pcre/include -I/opt/homebrew/opt/openssl@1.1/include'
      5. --with-ld-opt='-L/opt/homebrew/opt/pcre/lib -L/opt/homebrew/opt/openssl@1.1/lib'
      6. --conf-path=/opt/homebrew/etc/nginx/nginx.conf
      7. --pid-path=/opt/homebrew/var/run/nginx.pid
      8. --lock-path=/opt/homebrew/var/run/nginx.lock
      9. --http-client-body-temp-path=/opt/homebrew/var/run/nginx/client_body_temp
      10. --http-proxy-temp-path=/opt/homebrew/var/run/nginx/proxy_temp
      11. --http-fastcgi-temp-path=/opt/homebrew/var/run/nginx/fastcgi_temp
      12. --http-uwsgi-temp-path=/opt/homebrew/var/run/nginx/uwsgi_temp
      13. --http-scgi-temp-path=/opt/homebrew/var/run/nginx/scgi_temp
      14. --http-log-path=/opt/homebrew/var/log/nginx/access.log
      15. --error-log-path=/opt/homebrew/var/log/nginx/error.log
      16. --with-compat
      17. --with-debug
      18. --with-http_addition_module
      19. --with-http_auth_request_module
      20. --with-http_dav_module
      21. --with-http_degradation_module
      22. --with-http_flv_module
      23. --with-http_gunzip_module
      24. --with-http_gzip_static_module
      25. --with-http_mp4_module
      26. --with-http_random_index_module
      27. --with-http_realip_module
      28. --with-http_secure_link_module
      29. --with-http_slice_module
      30. --with-http_ssl_module
      31. --with-http_stub_status_module
      32. --with-http_sub_module
      33. --with-http_v2_module
      34. --with-ipv6
      35. --with-mail
      36. --with-mail_ssl_module
      37. --with-pcre
      38. --with-pcre-jit
      39. --with-stream
      40. --with-stream_realip_module
      41. --with-stream_ssl_module
      42. --with-stream_ssl_preread_module