2.4 编译安装 : configure / make / make install

本文详细介绍了Nginx的编译安装流程,包括使用configure检查系统环境、make进行编译、make install部署,以及生成的配置参数和模块结构。深入解析了HTTP rewrite模块依赖的PCRE库等问题。

2.4 编译安装 : configure / make / make install

./configure

检测系统内核和已经安装的软件,参数解析,生成MakeFile文件等等  — 编译nginx - 编译不通过会包缺少软件; 依次安装软件 
问题:
the HTTP rewrite module requires the PCRE library

make

根据configure生成的MakeFile编译Nginx工程,并生成目标文件,最终的二进制文件

make insatll

根据configure执行配置的参数,把nginx部署到指定的文件目录(包括相关目录的创建;二进制文件、配置文件的复制)

生成配置的参数

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
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"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

configure执行成功生成的objs的路径

├── autoconf.err      //保存编译过程产生的结果
├── autotest.c
├── Makefile           //用于make命令来编译,以及make install 根据参数来部署
├── ngx_auto_config.h
├── ngx_auto_headers.h
├── ngx_modules.c     
└── src               //存放编译时产生的目标文件
    ├── core
    ├── event
    │   └── modules
    ├── http
    │   ├── modules
    │   │   └── perl
    │   └── v2
    ├── mail
    ├── misc
    ├── os
    │   ├── unix
    │   └── win32
    └── stream

ngx_modules.c 结构

char *ngx_module_names[] = {
    "ngx_core_module",
    "ngx_errlog_module",
    "ngx_conf_module",
    "ngx_regex_module",
    "ngx_events_module",
    "ngx_event_core_module",
    "ngx_epoll_module",
    "ngx_http_module",
    "ngx_http_core_module",
    "ngx_http_log_module",
    "ngx_http_upstream_module",
    "ngx_http_static_module",
    "ngx_http_autoindex_module",
    "ngx_http_index_module",
    "ngx_http_mirror_module",
    "ngx_http_try_files_module",
    "ngx_http_auth_basic_module",
    "ngx_http_access_module",
    "ngx_http_limit_conn_module",
    "ngx_http_limit_req_module",
    "ngx_http_geo_module",
    "ngx_http_map_module",
    "ngx_http_split_clients_module",
    "ngx_http_referer_module",
    "ngx_http_rewrite_module",
    "ngx_http_proxy_module",
    "ngx_http_fastcgi_module",
    "ngx_http_uwsgi_module",
    "ngx_http_scgi_module",
    "ngx_http_memcached_module",
    "ngx_http_empty_gif_module",
    "ngx_http_browser_module",
    "ngx_http_upstream_hash_module",
    "ngx_http_upstream_ip_hash_module",
    "ngx_http_upstream_least_conn_module",
    "ngx_http_upstream_random_module",
    "ngx_http_upstream_keepalive_module",
    "ngx_http_upstream_zone_module",
    "ngx_http_write_filter_module",
    "ngx_http_header_filter_module",
    "ngx_http_chunked_filter_module",
    "ngx_http_range_header_filter_module",
    "ngx_http_gzip_filter_module",
    "ngx_http_postpone_filter_module",
    "ngx_http_ssi_filter_module",
    "ngx_http_charset_filter_module",
    "ngx_http_userid_filter_module",
    "ngx_http_headers_filter_module",
    "ngx_http_copy_filter_module",
    "ngx_http_range_body_filter_module",
    "ngx_http_not_modified_filter_module",
    NULL
};
<think>我们正在讨论的是源码安装软件的步骤问题。根据用户提供的引用内容,可以明确源码安装的标准步骤确实是三个主要步骤:配置(./configure)、编译make)、安装make install)。同时,在安装完成后,还可以执行make clean来清理临时文件。 用户的问题:**源码安装软件时依次执行 ./configuremakemake install 步骤是否正确?** 根据引用内容: - 引用[1]和[2]都明确指出了这三个步骤:./configure(配置并生成Makefile),make编译),make install安装)。 - 引用[3]提到,./configure的作用是检测系统配置,生成makefile文件,以便进行编译安装。 - 引用[4]也说明了Linux安装应用程序的一般步骤:configuremakemake install,然后make clean。 因此,答案是肯定的:正确。 但需要注意的是,并非所有源码包都完全一样: - 有些项目可能使用CMake等其它工具,此时步骤可能是先创建build目录,然后运行cmake,再make。 - 有些项目可能没有configure脚本,而是直接有Makefile,那么就可以跳过configure步骤,直接makemake install。 - 有些项目可能使用autoconf工具生成的configure脚本,那么就必须先运行./configure。 根据引用[3]中的提示:可以先ls查看目录下是否有configureMakefile文件。如果有configure,就执行./configure;如果有Makefile,就直接执行make。 所以,在回答中我们应该确认标准步骤的正确性,同时指出可能存在的变体情况。 此外,用户提供的引用中还提到: - 在运行./configure时,可以通过参数指定安装路径,例如:`./configure --prefix=/your/path`(引用[2])。 - 安装后如果需要卸载,可以查看`install_manifest.txt`文件,然后逐个删除其中列出的文件(引用[3])。 因此,回答结构可以如下: 1. 明确肯定标准步骤的正确性。 2. 解释每个步骤的作用(根据引用内容)。 3. 补充注意事项(如权限问题、卸载方法等)。 4. 生成相关问题。 注意:回答中如果引用到用户提供的引用内容,需要在句尾添加引用标识[^n]。 </think>是的,源码安装软件时依次执行 `./configure`、`make`、`make install` 这三个步骤完全正确,这是Linux/Unix系统中标准的源代码编译安装流程[^3]。以下是详细解析: ### 标准安装步骤及作用 1. **`./configure`** - 检测系统环境和依赖关系 - 生成定制化的 `Makefile` 文件(若源码包只含 `Makefile.in` 则必须此步骤)[^2] - 可通过参数自定义安装路径:`./configure --prefix=/your/path`[^2] ```bash ./configure --prefix=/usr/local/myapp ``` 2. **`make`** - 根据 `Makefile` 指令编译源代码 - 生成可执行文件和二进制库 - 编译过程占用临时磁盘空间(后续需清理)[^4] 3. **`make install`** - 将编译好的文件复制到系统目录 - 默认安装到 `/usr/local/bin` 等系统路径[^2] - 可能需要管理员权限:`sudo make install`[^2] ```bash sudo make install ``` 4. **(可选)`make clean`** - 删除编译产生的临时文件 - 释放磁盘空间[^1][^4] ### 补充说明 - **路径验证**:安装后可通过 `cat install_manifest.txt` 查看所有安装文件的路径[^3] - **卸载方法**:使用安装清单反向删除 ```bash cat install_manifest.txt | sudo xargs rm ``` - **替代方案**:现代Linux系统推荐优先使用包管理器(如`apt`/`yum`)自动解决依赖关系[^3] ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值