Mac、Ubuntu、Linux源码编译安装Nginx
nanshan 2024-11-17 14:12 18 浏览 0 评论
1、下载Nginx源代码
http://nginx.org/en/download.html
mkdir sources && cd sources
wget http://nginx.org/download/nginx-1.19.7.tar.gz
tar -zxvf nginx-1.19.7.tar.gz && mkdir ../nginx-1.19.7
2、安装依赖
centos:
yum -y install pcre-devel zlib-devel openssl openssl-devel
ubuntu:
apt -y install libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev
Mac:
brew install cmake gcc gd zlib openssl pcre perl
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.zip
wget https://www.openssl.org/source/openssl-1.1.1j.tar.gz
unzip pcre-8.44.zip && tar -zxvf openssl-1.1.1j.tar.gz
3、安装外部模块
# 健康检查模块
git clone http://github.com/yaoweibin/nginx_upstream_check_module
cd nginx-1.19.7 && patch -p1 < ../nginx_upstream_check_module/check_1.12.1+.patch && cd ..
修改代码
vim nginx_upstream_check_module/ngx_http_upstream_check_module.c
将55行的 pragma pack() 改为 pragma pack(pop)
4、编译安装
cd nginx-1.19.7
./configure \
--prefix=/Users/horace/software/nginx-1.19.7 \
--with-http_ssl_module \
--add-module=../nginx_upstream_check_module \
--with-openssl=../openssl-1.1.1j \
--with-pcre-jit \
--with-pcre=../pcre-8.44 \
--with-file-aio \ # Mac下不支持
--with-ipv6 \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-stream_ssl_preread_module \
--with-http_addition_module \
--with-http_image_filter_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-http_perl_module=dynamic \
--with-http_auth_request_module \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-debug
make install
5、编译参数说明
参数 | 说明 |
--prefix | 安装目录 |
--with-http_ssl_module | 增加Https支持 |
--add-module | 添加构建外部模块 |
--with-openssl | 设置OpenSSL源码路径 |
--with-pcre-jit | 使用即时编译构建pcre库 |
--with-pcre | 设置pcre源码路径 |
--with-file-aio | 支持在FreeBSD和Linux上使用异步IO |
--with-ipv6 | 添加IPv6的支持 |
--with-http_v2_module | 添加Http v2支持 |
--with-http_realip_module | 模块将客户端地址更改为在指定的标头字段中发送的地址 |
--with-stream_ssl_preread_module | 模块允许从ClientHello 消息中提取信息, 而无需终止SSL/TLS |
--with-http_addition_module | 该模块在响应之前和之后添加文本 |
--with-http_image_filter_module | 该 模块可以转换JPEG,GIF,PNG和WebP格式的图像 |
--with-http_sub_module | 该 模块通过将一个指定的字符串替换为另一个指定的字符串来修改响应 |
--with-http_dav_module | 模块通过WebDAV协议提供文件管理自动化 |
--with-http_flv_module | 为Flash Video(FLV)文件提供伪流服务器端支持 |
--with-http_mp4_module | 为MP4文件提供伪流服务器端支持 |
--with-http_gunzip_module | 支持为不支持“ gzip”编码方法的客户端构建ngx_http_gunzip_module 模块,该 模块使用“ Content-Encoding: gzip”解压缩响应 |
--with-http_gzip_static_module | 支持发送扩展名为“.gz”的预压缩文件 |
--with-http_random_index_module | 模块处理以斜杠'/'结尾的请求,并在目录中选择一个随机文件作为索引文件 |
--with-http_secure_link_module | 用于检查请求的连接 |
--with-http_degradation_module | |
--with-http_slice_module | 将请求拆分为多个子请求,每个子请求都返回一定范围的响应。该模块提供了更有效的大响应缓存 |
--with-http_stub_status_module | 提供对基本状态信息的访问 |
--with-http_perl_module | 支持嵌入perl模块 |
--with-http_auth_request_module | 基于子请求的结果实现客户端授权 |
--with-mail | 启用POP3/IMAP4/SMTP 邮件代理服务器。 |
--with-mail_ssl_module | 邮件代理启用SSL |
--with-stream | 用于通用TCP/UDP代理和负载平衡的 流模块 |
--with-stream_ssl_module | 流模块启用SSL |
--with-debug | 启用调试日志 |
6、基本配置
#user nobody;
# 工作进程数,取值为auto或者实际数值
worker_processes 10;
# 配置日志级别
error_log logs/error.log info;
pid logs/nginx.pid;
# 连接相关处理的配置
events {
# 每个进程打开的连接数,这里包括了代理服务器的连接数与客户端的连接数的总和
worker_connections 1024;
}
# Http服务的相关配置
http {
# 包含另一个文件内容
include mime.types;
# 定义响应的默认mime类型
default_type application/octet-stream;
# 指定日志格式
log_format main escape=json '{"timeIso8601": "$time_iso8601", "method": "$request_method", "remoteAddr": "$remote_addr", "uri": "$request_uri", "useTime": "$request_time", "status": "$status", "serverAddr": "$server_addr", "serverName": "$server_name", "serverPort": "$server_port", "upstreamAddr": "$upstream_addr", "requestLength": "$request_length", "bodyBytesSent": "$body_bytes_sent", "referer": "$http_referer", "remoteUser": "$remote_user", "userAgent": "$http_user_agent", "connection": "$connection", "connectionRequests": "$connection_requests", "xForwardedFor": "$http_x_forwarded_for"}';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
charset utf-8;
access_log logs/localhost.access.log main;
# 访问规则配置
location / {
root html;
index index.html index.htm;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include website/*.conf;
}
7、配置代理服务
添加以下配置到website/demo.horace.cn.conf文件中
upstream upstream_test {
server 127.0.0.1:1577;
}
server {
listen 80;
access_log logs/demo.horace.cn.log main;
server_name demo.horace.cn;
location / {
proxy_pass http://upstream_test;
}
}
8、启动与关闭
nginx 启动
nginx -s stop 快速关闭
nginx -s quit 优雅关闭
nginx -s reload 重新加载配置
相关推荐
- Linux/Unix 系统中非常常用的命令
-
Linux/Unix系统中非常常用的命令,它们是进行文件操作、文本处理、权限管理等任务的基础。下面是对这些命令的简要说明:**文件操作类:*****`ls`(list):**列出目录内容,显...
- 教你如何在Linux中删除分区(CLI篇)
-
文接上篇,继续以Ubuntu系统为例。删除分区前,急得重要数据备份!备份!备份用命令操作分区,用的最多的莫过于fdisk了,几乎所有的Linux发行版都默认带有fdisk。首先要知道的是,你想删除的分...
- 敲完就让你提桶跑路的Linux命令(敲完就让你提桶跑路的linux命令是什么)
-
不谨慎可能就会让你提桶的Linux命令!!!删除文件rm-rf该命令是删除文件或文件夹等最快的方式之一。删除后的内容很难恢复,如果删除系统文件可能会导致系统崩坏。>rm-rf/#强制...
- Log文件可以删除吗(taxukeylog文件可以删除吗)
-
Log文件(日志文件)是否可以删除取决于具体场景和文件类型。以下是详细分析和建议:一、哪些Log文件可以删除?非关键应用日志用户级应用日志:如浏览器缓存日志、游戏临时日志等,通常不影响系统运行,可定期...
- Linux 删除空目录(linux直接删除目录)
-
rmdir命令用来删除空目录。当目录不再被使用时,或者磁盘空间已到达使用限定值,就需要删除失去使用价值的目录。利用rmdir命令可以从一个目录中删除一个或多个空的子目录。该命令从一个目录中删除一个或...
- 在 Windows 11 或 10 上删除、创建和格式化分区
-
在Windows11或10上删除、创建和格式化分区假设您的现有电脑使用的是传统硬盘,但现在您想再添加一个硬盘或SSD。当然,后者将用于启动操作系统,而前者将作为纯数据存储。在成功将操作系统...
- 如何使用 Apt Clean 命令清除 APT 缓存?
-
APT(AdvancedPackageTool)是Debian系Linux发行版的包管理工具,用于处理软件包的安装、升级和依赖管理。在使用apt命令(如aptinstall、apt...
- Linux 磁盘空间不够用?5 招快速清理文件,释放 10GB 空间不是梦!
-
刚收到服务器警告:磁盘空间不足90%!装软件提示Nospaceleftondevice!连日志都写不进去,系统卡到崩溃?别慌!今天教你5个超实用的磁盘清理大招,从临时文件到无用软件一键搞定...
- Linux清空日志方法(linux怎么清理日志)
-
方法1:使用>重定向>/path/to/logfile或(需要权限时):sudosh-c'>/var/log/logfile'方法2:使用trun...
- 如何在Eclipse中搭建Zabbix源码的调试和开发环境
-
Zabbix是一款非常优秀的企业级软件,被设计用于对数万台服务器、虚拟机和网络设备的数百万个监控项进行实时监控。Zabbix是开放源码和免费的,这就意味着当出现bug时,我们可以很方便地通过调试源码来...
- Linux操作系统之常用命令(linux操作系统之常用命令有哪些)
-
Linux操作系统一、常用命令1.系统(1)系统信息arch显示机器的处理器架构uname-m显示机器的处理器架构uname-r显示正在使用的内核版本dmidecode-q显示硬件系...
- 理解linux内核的vmlinuz和initrd(linux内核原理及分析)
-
Originaladdress:http://www.chenjunlu.com/2010/11/understanding-of-vmlinuz-initrd-and-system-map/1....
- Linux纯干货知识总结|面试专用(linux面试宝典)
-
学习Linux的重要性相信不用我多说大家也明白,以下是小编总结的常用Linux基础知识以及面试常问的Linux命令,希望能帮助大家更规范地理解和使用~绝对路径和相对路径绝对路径以正斜杠开始完整的文件的...
- Linux基础知识之启动流程分析(简述linux启动流程)
-
Linux系统启动原理:1.poweron开机。2.开机自检:电脑开机后首先加载BIOS(BasicInput/OutputSystem基本输入输出系统)。BIOS程序首先检查计算机能否满足运...
- Java程序员必备——Linux的面试常见问题及面试题!你知道多少?
-
一.常用命令1.编辑相关①.awkNF:字段总数NR:第几行数据FS:分隔字符②.sed-n-i直接修改4a:在第四行后添加4i:在第四行前插入1,5csting:用sting替换1到5行...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- linux 查询端口号 (58)
- docker映射容器目录到宿主机 (66)
- 杀端口 (60)
- yum更换阿里源 (62)
- internet explorer 增强的安全配置已启用 (65)
- linux自动挂载 (56)
- 禁用selinux (55)
- sysv-rc-conf (69)
- ubuntu防火墙状态查看 (64)
- windows server 2022激活密钥 (56)
- 无法与服务器建立安全连接是什么意思 (74)
- 443/80端口被占用怎么解决 (56)
- ping无法访问目标主机怎么解决 (58)
- fdatasync (59)
- 405 not allowed (56)
- 免备案虚拟主机zxhost (55)
- linux根据pid查看进程 (60)
- dhcp工具 (62)
- mysql 1045 (57)
- 宝塔远程工具 (56)
- ssh服务器拒绝了密码 请再试一次 (56)
- ubuntu卸载docker (56)
- linux查看nginx状态 (63)
- tomcat 乱码 (76)
- 2008r2激活序列号 (65)