debian安装Nginx

编译安装Nginx

复制代码
sudo apt-get update

环境准备

编译Nginx需要gcc+的环境支持,build-essential内包含gcc+套件,所以我们安装build-essential即可:

复制代码
sudo apt-get install build-essential

因为nginx.conf中使用了正则表达式,所以编译Nginx时就需要把PCRE库编译进Nginx,而Debian内安装PCRE库,可以这样安装:

复制代码
sudo apt-get install libpcre3 libpcre3-dev

当热,Nginx编译过程和Http相应过程还需要gzip格式的压缩,所以我们还需要安装zlib库用于对HTTP包的内容做gzip格式的压缩,可以这样安装:

复制代码
sudo apt-get install zlib1g-dev

最后,现在SSL协议很重要,Chrome等主流浏览器,都开始默认相应HTTPS了,所以OpenSSL编译环境也很重要:

复制代码
sudo apt-get install openssl libssl-dev

另外,如果你不想安装OpenSSL,或者想指定第三方OpenSSL用于编译,可以在Nginx编译时添加编译参数:--with-openssl

下载Nginx源码

接下来,我们下载并解压Nginx的源码,Nginx源码下载官方地址:

http://nginx.org/en/download.html

开发环境,我们使用最新稳定版本Nginx:

复制代码
# 下载Nginx 1.20.1源码(Stable稳定版本)
wget "http://nginx.org/download/nginx-1.20.1.tar.gz"
# 使用tar命令解压
tar -xf nginx-1.20.1.tar.gz
# 进入解压后出现的目录,已备接下来的编译
cd nginx-1.20.1

编译Nginx
首先,我们需要生成makefile文件,编译时候的参数可以参考官方Nginx文档:

http://nginx.org/en/docs/configure.html

我自己编译Nginx时候,选择的参数一般是:

./configure \--prefix=/etc/nginx \--sbin-path=/usr/sbin/nginx \--conf-path=/etc/nginx/nginx.conf \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--pid-path=/var/run/nginx.pid \--lock-path=/var/run/nginx.lock \--http-client-body-temp-path=/var/cache/nginx/client_temp \--http-proxy-temp-path=/var/cache/nginx/proxy_temp \--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \--http-scgi-temp-path=/var/cache/nginx/scgi_temp \--user=www \--group=www \--with-file-aio \--with-threads \--with-http_addition_module \--with-http_auth_request_module \--with-http_dav_module \--with-http_flv_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_mp4_module \--with-http_random_index_module \--with-http_realip_module \--with-http_secure_link_module \--with-http_slice_module \--with-http_ssl_module \--with-http_stub_status_module \--with-http_sub_module \--with-http_v2_module \--with-mail \--with-mail_ssl_module \--with-stream \--with-stream_realip_module \--with-stream_ssl_module \--with-stream_ssl_preread_module 

其中:

  • --prefix:Nginx主要安装路径,后续Nginx子目录依照这个变量展开
  • --user:设置Nginx进程启动时,所属的用户
  • --group:设置Nginx进程启动时,所属的用户组

如果没问题,会显示信息:

Configuration summary + using threads + using system PCRE library + using system OpenSSL library + using system zlib library nginx path prefix: "/etc/nginx" nginx binary file: "/usr/sbin/nginx" nginx modules path: "/etc/nginx/modules" nginx configuration prefix: "/etc/nginx" nginx configuration file: "/etc/nginx/nginx.conf" nginx pid file: "/var/run/nginx.pid" nginx error log file: "/var/log/nginx/error.log" nginx http access log file: "/var/log/nginx/access.log" nginx http client request body temporary files: "/var/cache/nginx/client_temp" nginx http proxy temporary files: "/var/cache/nginx/proxy_temp" nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp" nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp" nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"

之后,执行编译即可:

复制代码
make && make install

编译删除Nginx

复制代码
# 关闭Nginx
nginx -s quit
# 删除Nginx
sudo rm -rf /etc/nginx
相关推荐
呉師傅25 分钟前
UPS滴滴告警!如何测量UPS电池内阻【UPS学习】
运维·服务器·网络·学习·电脑
tedcloud1231 小时前
wifi-densepose部署教程:构建无线人体感知系统
服务器·javascript·网络·typescript·ocr
AC赳赳老秦1 小时前
OpenClaw碎片时间利用:设置轻量化自动化任务,高效利用职场碎片时间
java·大数据·运维·服务器·数据库·自动化·openclaw
lqj_本人2 小时前
鸿蒙electron跨端框架PC课业板实战:课程、截止时间、提交物和风险都放到桌面上
服务器·electron·harmonyos
Bert.Cai2 小时前
Linux tee命令详解
linux·运维·服务器
楷哥爱开发3 小时前
演唱会自动化抢票如何提高成功率?票务住宅IP与配置指南
服务器·前端·php
测试员周周3 小时前
【Appium 系列】第17节-XMind用例转换 — 从思维导图到 YAML
java·服务器·人工智能·单元测试·appium·测试用例·xmind
cui_ruicheng3 小时前
Linux网络编程(七):TCP Socket编程与EchoServer
linux·服务器·网络·tcp/ip
feasibility.3 小时前
nvidia-smi 失灵,显存凭空消失?—— NVML 驱动版本错配的记录
linux·运维·服务器·经验分享·nvidia·驱动
雨的旋律20993 小时前
keepalived + LVS NAT模式
服务器·网络·lvs