Ubuntu 编译安装 nginx

Ubuntu 22.04.1 LTS 编译安装 nginx-1.22.1

安装依赖

复制代码
sudo apt install libgd-dev

下载nginx

wget http://nginx.org/download/nginx-1.22.1.tar.gz

解压nginx

tar -zvxf nginx-1.22.1.tar.gz

编译安装

cd nginx-1.22.1

编译并指定安装位置,执行安装之后会创建指定文件夹/www/env/nginx

复制代码
./configure --prefix=/www/env/nginx \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--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_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module 

问题1:

./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre= option. PCRE库

PCRE库支持正则表达式。如果我们在配置文件nginx.conf中使用了正则表达式,那么在编译Nginx时就必须把PCRE库编译进Nginx,因为Nginx的HTTP模块需要靠它来解析正则表达式。另外,pcre-devel是使用PCRE做二次开发时所需要的开发库,包括头文件等,这也是编译Nginx所必须使用的。可以这样安装:

sudo apt update sudo apt install libpcre3 libpcre3-dev 问题2:

./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl= option OpenSSL库

如果服务器不只是要支持HTTP,还需要在更安全的SSL协议上传输HTTP,那么需要拥有OpenSSL。另外,如果我们想使用MD5、SHA1等散列函数,那么也需要安装它。可以这样安装:

sudo apt-get install openssl libssl-dev 执行编译并安装

复制代码
make && make install

nginx常用命令 常用命令 nginx -s reload 修改配置后重新加载生效 nginx -s stop 快速停止nginx nginx -s start 启动nginx nginx -s quit 完整有序的停止nginx nginx -v 查看nginx的版本 nginx -V 查看版本和nginx的配置选项 nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确 nginx -s reopen 重新打开日志文件

相关推荐
韩楚风3 小时前
【linux 多进程并发】linux进程状态与生命周期各阶段转换,进程状态查看分析,助力高性能优化
linux·服务器·性能优化·架构·gnu
陈苏同学3 小时前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
Ambition_LAO3 小时前
解决:进入 WSL(Windows Subsystem for Linux)以及将 PyCharm 2024 连接到 WSL
linux·pycharm
Pythonliu73 小时前
茴香豆 + Qwen-7B-Chat-Int8
linux·运维·服务器
你疯了抱抱我3 小时前
【RockyLinux 9.4】安装 NVIDIA 驱动,改变分辨率,避坑版本。(CentOS 系列也能用)
linux·运维·centos
追风赶月、3 小时前
【Linux】进程地址空间(初步了解)
linux
栎栎学编程3 小时前
Linux中环境变量
linux
挥剑决浮云 -4 小时前
Linux 之 安装软件、GCC编译器、Linux 操作系统基础
linux·服务器·c语言·c++·经验分享·笔记
小O_好好学5 小时前
CentOS 7文件系统
linux·运维·centos
苹果醋35 小时前
快速玩转 Mixtral 8x7B MOE大模型!阿里云机器学习 PAI 推出最佳实践
spring boot·nginx·毕业设计·layui·课程设计