Nginx 源码编译
1、首先在官网下载Nginx 发布版的源码,
Nginx 官网下载的地址是 :http://www.nginx.org/en/download.html
因为Nginx官网支持SVN,可以简单方便的使用svn下载的是Nginx 1.3.0 版源码编译,命令如下:
svn checkout svn://svn.nginx.org/nginx/tags/release-1.3.0
2、configure信息的配置说明
简单浏览下载的源码后,可以发现和编译相关的信息文件在auto目录下,其中configure也在这个目录下。用vi打开configure,可以发现它应该放在源码的顶级目录下,移动configure 命令如下:
mv configure ../
再回到顶级目录,运行configure 即可生成Makefile 文件。这里需要注意的是,根据自己的需求设置configure的参数来生成Makefile文件。例如,如果你需要Nginx 支持https协议,那么configure的命令需要加上参数 --with-http_ssl_module ,当然你的linux系统中也要安装相应的OPENSSL库,具体命令: ./configure --with-http_ssl_module。细心的我们可以看到,没加这个参数生成Makefile文件时,显示的信息中有:+ OpenSSL library is not used ,而添加参数 --with-http_ssl_module 后,则是:using system OpenSSL library。其他模块的安装类是。在此,也可以知道Nginx 1.3 版本中可能要用的的支持库有
PCRE library
OpenSSL library
OpenSSL library
OpenSSL library
zlib library
补充说明下的是默认下Nginx相关文件安装路径的信息是:
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
也可以通过configure 加入相应的参数修改这些信息。
3、在根据自己需求配置完configure文件,生成Makefile文件后,就可以执行make命令,即可完成Nginx源代码的编译。同时用命令 make install 进行安装部署。若是ubuntu系统由于需要对系统目录进行操作需要sudo(其他操作若出现权限不够 Permission denied时都需要)。在默认安装路径的情况下,启动Nginx的命令如下:/usr/local/nginx/sbin/nginx。打开浏览器输入localhost 出现:
Welcome to nginx!
的欢迎页面,至此Nginx源码编译安装完成。关闭nginx命令:/usr/local/nginx/sbin/nginx -s stop
4、附上网上找到的一些configure 参数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #Nginx安装路径。如果没有指定,默认为 /usr/local/nginx。 --prefix=PATH #Nginx可执行文件安装路径。只能安装时指定,如果没有指定,默认为PATH/sbin/nginx。 --sbin-path=PATH #在没有给定-c选项下默认的nginx.conf的路径。如果没有指定,默认为PATH/conf/nginx.conf。 --conf-path=PATH #在nginx.conf中没有指定pid指令的情况下,默认的nginx.pid的路径。如果没有指定,默认为 PATH/logs/nginx.pid。 --pid-path=PATH #nginx.lock文件的路径。 --lock-path=PATH #在nginx.conf中没有指定error_log指令的情况下,默认的错误日志的路径。如果没有指定,默认为 PATH/logs/error.log。 --error-log-path=PATH #在nginx.conf中没有指定access_log指令的情况下,默认的访问日志的路径。如果没有指定,默认为 PATH/logs/access.log。 --http-log-path=PATH #在nginx.conf中没有指定user指令的情况下,默认的nginx使用的用户。如果没有指定,默认为 nobody。 --user=USER #在nginx.conf中没有指定user指令的情况下,默认的nginx使用的组。如果没有指定,默认为 nobody。 --group=GROUP #指定编译的目录 --builddir=DIR #启用 rtsig 模块 --with-rtsig_module #允许或不允许开启SELECT模式,如果configure没有找到合适的模式,比如,kqueue(sun os)、epoll(linux kenel 2.6+)、rtsig(实时信号) --with-select_module(--without-select_module) #允许或不允许开启POLL模式,如果没有合适的,则开启该模式。 --with-poll_module(--without-poll_module) #开启HTTP SSL模块,使NGINX可以支持HTTPS请求。这个模块需要已经安装了OPENSSL,在DEBIAN上是libssl-dev --with-http_ssl_module --with-http_realip_module #启用 ngx_http_realip_module --with-http_addition_module #启用 ngx_http_addition_module --with-http_sub_module #启用 ngx_http_sub_module --with-http_dav_module #启用 ngx_http_dav_module --with-http_flv_module #启用 ngx_http_flv_module --with-http_stub_status_module #启用 "server status" 页 --without-http_charset_module #禁用 ngx_http_charset_module --without-http_gzip_module #禁用 ngx_http_gzip_module. 如果启用,需要 zlib 。 --without-http_ssi_module #禁用 ngx_http_ssi_module --without-http_userid_module #禁用 ngx_http_userid_module --without-http_access_module #禁用 ngx_http_access_module --without-http_auth_basic_module #禁用 ngx_http_auth_basic_module --without-http_autoindex_module #禁用 ngx_http_autoindex_module --without-http_geo_module #禁用 ngx_http_geo_module --without-http_map_module #禁用 ngx_http_map_module --without-http_referer_module #禁用 ngx_http_referer_module --without-http_rewrite_module #禁用 ngx_http_rewrite_module. 如果启用需要 PCRE 。 --without-http_proxy_module #禁用 ngx_http_proxy_module --without-http_fastcgi_module #禁用 ngx_http_fastcgi_module --without-http_memcached_module #禁用 ngx_http_memcached_module --without-http_limit_zone_module #禁用 ngx_http_limit_zone_module --without-http_empty_gif_module #禁用 ngx_http_empty_gif_module --without-http_browser_module #禁用 ngx_http_browser_module --without-http_upstream_ip_hash_module #禁用 ngx_http_upstream_ip_hash_module --with-http_perl_module - #启用 ngx_http_perl_module --with-perl_modules_path=PATH #指定 perl 模块的路径 --with-perl=PATH #指定 perl 执行文件的路径 --http-log-path=PATH #Set path to the http access log --http-client-body-temp-path=PATH #Set path to the http client request body temporary files --http-proxy-temp-path=PATH #Set path to the http proxy temporary files --http-fastcgi-temp-path=PATH #Set path to the http fastcgi temporary files --without-http #禁用 HTTP server --with-mail #启用 IMAP4/POP3/SMTP 代理模块 --with-mail_ssl_module #启用 ngx_mail_ssl_module --with-cc=PATH #指定 C 编译器的路径 --with-cpp=PATH #指定 C 预处理器的路径 --with-cc-opt=OPTIONS # --with-ld-opt=OPTIONS #Additional parameters passed to the linker. With the use of the system library PCRE in FreeBSD, it is necessary to indicate --with-ld-opt="-L /usr/local/lib". --with-cpu-opt=CPU #为特定的 CPU 编译,有效的值包括:pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64 --without-pcre #禁止 PCRE 库的使用。同时也会禁止 HTTP rewrite 模块。在 "location" 配置指令中的正则表达式也需要 PCRE 。 --with-pcre=DIR #指定 PCRE 库的源代码的路径。 --with-pcre-opt=OPTIONS #设置PCRE的额外编译选项。 --with-md5=DIR #使用MD5汇编源码。 --with-md5-opt=OPTIONS #Set additional options for md5 building. --with-md5-asm #Use md5 assembler sources. --with-sha1=DIR #Set path to sha1 library sources. --with-sha1-opt=OPTIONS #Set additional options for sha1 building. --with-sha1-asm #Use sha1 assembler sources. --with-zlib=DIR #Set path to zlib library sources. --with-zlib-opt=OPTIONS #Set additional options for zlib building. --with-zlib-asm=CPU #Use zlib assembler sources optimized for specified CPU, valid values are: pentium, pentiumpro --with-openssl=DIR #Set path to OpenSSL library sources --with-openssl-opt=OPTIONS #Set additional options for OpenSSL building --with-debug #启用调试日志 --add-module=PATH #Add in a third-party module found in directory PATH 在不同版本间,选项可能会有些许变化,请总是使用 . /configure --help 命令来检查一下当前的选项列表。 |

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)