# 1. 创建service目录
mkdir service
# 2. 进入service
cd service
# 3. 下载nginx
curl -o nginx-1.24.0.tar.gz https://nginx.org/download/nginx-1.24.0.tar.gz
# 4. 解压
tar -zxvf nginx-1.24.0.tar.gz
# 5. 进入nginx-1.24.0
cd nginx-1.24.0
# 6. 执行./configure
./configure
# 如果出现 ./configure: error: C compiler cc is not found
sudo apt-get install gcc
sudo apt-get install g++
./configure
# 如果出现 ./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 依赖
sudo apt-get install libpcre3-dev
./configure
# 如果出现 ./configure: error: the HTTP gzip module requires the zlib library.
# You can either disable the module by using --without-http_gzip_module
# option, or install the zlib library into the system, or build the zlib library
# statically from the source with nginx by using --with-zlib=<path> option.
# 需要安装zlib 依赖
sudo apt-get install zlib1g.dev
# 然后在执行
./configure
# 出现此内容说明执行成功
# Configuration summary
# + using system PCRE library
# + OpenSSL library is not used
# + using system zlib library
# nginx 提醒OpenSSL library没使用
# 安装OpenSSL library依赖
sudo apt-get install openssl
sudo apt-get install libssl-dev
# 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 --with-http_ssl_module --with-http_v2_module --with-stream
# 7. 编译
make
# -bash: make: command not found
sudo apt-get update
sudo apt-get install make
make
# 8. 安装
make install
# 9.启动nginx
nginx
-bash: nginx: 未找到命令
# 需要修改环境变量
# vim /etc/profile
# 在最后一排输入 export PATH=$PATH:/usr/local/nginx/sbin
# source /etc/profile
Ubuntu环境安装nginx-1.24.0
于 2024-02-04 18:28:10 首次发布