Debian 12 源码编译安装nginx-1.28.0
技术 2025年10月31日 作者: 管振佐
56 阅读 0 评论

Debian 12 源码编译安装nginx-1.28.0

1、下载nginx-1.28.0

wget https://nginx.org/download/nginx-1.28.0.tar.gz

2、解压缩并进入安装包

tar -zxvf nginx-1.28.0.tar.gz && cd nginx-1.28.0

3、编译

./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/var/run/nginx.pid --user=www --group=www --with-select_module --with-poll_module --with-threads --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_v3_module --with-http_realip_module --with-http_addition_module --with-http_mp4_module --with-http_auth_request_module --with-http_secure_link_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module

编译参数说明:

  1. --prefix
  2. --sbin-path
  3. --conf-path
  4. --pid-path
  5. --user
  6. --group
  7. --with-select_module
  8. --with-poll_module

 

 

如果没有提前安装必要的依赖,会报错。报错信息以及解决办法:

./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=<path> option.

此错误信息表示,系统缺失PCRE库。PCRE库是一个正则表达式库。Nginx的HTTP重写模块会用到PCRE库处理正则表达式。解决方法1:sudo apt install libpcre3 libpcre3-dev

./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=<path> option.

这个错误表示 Nginx 的 SSL 模块需要 OpenSSL 库。解决方法1:sudo apt-get install libssl-dev

2025年11月12日进行新服务器的安装时,仅遇到了这些错误,如果有遇到其他错误,则安装对应的依赖包即可

4、安装

make && make install

进行到这一步,nginx已经完成了安装,接下来就是一些基础设置和安全设置

5、配置服务

5.1设置系统服务,使用systemctl进行启动与停止等维护操作

5.2设置开机自动启动

5.3基础设置

修改user  user www-data www-data;

配置worker_precesser 1; 此配置根据实际情况进行配置,其他参数:auto 数字,2为2核

开启日志记录以及日志保存位置:

error_log logs/error.log; 

error_log logs/error.log notice;

error_log logs/error.log info;  

在http 取消 log_format main的注释

不显示版本号:server_tokens off;

 

 

 

 

标签:

评论 (0)

验证码
评论需要审核后才会显示

暂无评论,快来抢沙发吧!

文章信息

分类 技术
发布时间 2025年10月31日
作者 管振佐
浏览量 56 次
标签