Nginx(tar安装)
先安装依赖
sh
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel gd-devel
apt update
add-apt-repository ppa:longsleep/golang-backports
libxslt-dev
libxslt
apt install build-essential libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev libxslt1-dev libgd-dev libgeoip-dev libxml2 libxml2-dev
# 问题1 libicu-dev : Depends: libicu70 (= 70.1-2) but 70.1-2ubuntu1 is to be installed
首先,安装正确版本的 libicu70:
sudo apt-get install libicu70=70.1-2
这将会降级到所需的版本。你需要确认降级,输入 Y 确认。
首先,安装 aptitude(如果你的系统没有安装):
sudo apt-get install aptitude
后运行以下命令安装 libicu-dev:
sudo aptitude -y install libicu-dev
uuid-dev : Depends: libuuid1 (= 2.37.2-4ubuntu3) but 2.37.2-4ubuntu3.2 is to be installed
,安装正确版本的 libuuid1: 执行以下命令来降级到所需的版本(将 "2.37.2-4ubuntu3" 替换为你需要的版本):
sudo apt-get install libuuid1=2.37.2-4ubuntu3
首先,安装 aptitude(如果你的系统没有安装):
sudo apt-get install aptitude
然后运行以下命令安装 uuid-dev:
sudo aptitude -y install uuid-dev
下载解压nginx
sh
wget https://nginx.org/download/nginx-1.25.3.tar.gz
tar -zxvf nginx-1.25.3.tar.gz
配置并编译
参考地址 https://docshome.gitbook.io/nginx-docs/readme/cong-yuan-ma-gou-jian-nginx
参数解读
sh
# 例 安装nginx目录为 /server/nginx-1.19.7
./configure \
# 设置一个非特权用户名称,其凭据将由工作进程使用。安装后,可以在 nginx.conf 配置文件中使用 user 指令更改名称。默认的用户名为 nobody。
--user=qolome \
# 设置一个组的名称,其凭据将由工作进程使用。安装后,可以在 nginx.conf 配置文件中使用 user 指令更改名称。默认情况下,组名称设置为一个非特权用户的名称。
--group=qolome \
# 安装路径前缀
--prefix=/server/nginx \
# 设置 nginx.conf 配置文件的名称。如果需要,nginx 可以使用不同的配置文件启动,方法是使用命令行参数 -c 指定文件。默认情为 prefix/conf/nginx.conf
--conf-path=/server/nginx/conf/nginx.conf \
# 设置存储主进程的进程 ID 的 nginx.pid 文件名称。安装后,可以在 nginx.conf 配置文件中使用 pid 指令更改文件名。默认文件名为 prefix/logs/nginx.pid。
--pid-path=/server/nginx/nginx.pid \
# 设置锁文件的名称前缀。安装后,可以在 nginx.conf 配置文件中使用 lock_file 指令更改对应的值。默认值为 prefix/logs/nginx.lock。
--lock-path=/server/nginx/lock/nginx.lock \
# 设置 可执行文件的名称。此名称仅在安装过程中使用。默认为 prefix/sbin/nginx。
--sbin-path=/server/nginx/sbin/nginx \
# 定义将安装 nginx 动态模块的目录 默认情况下 prefix/modules
--modules-path=/server/nginx/modules \
# 设置主要错误、警告和诊断文件的名称。安装后,可以在 nginx.conf 配置文件中使用 error_log 指令更改文件名。默认情况下,文件名为 prefix/logs/error.log。
--error-log-path=/server/nginx/logs/error.log \
# 设置 HTTP 服务器主请求日志文件名称。安装后,可以在 nginx.conf 配置文件中使用 access_log 指令更改文件名。默认情况下,文件名为 prefix/logs/access.log。
--http-log-path=/server/nginx/logs/access.log \
# 定义用于存储保存客户端的请求主体的临时文件的目录。安装后,可以使用client_body_temp_path 指令在nginx.conf配置文件中始终更改目录。默认的目录名为 prefix/client_body_temp。
--http-client-body-temp-path=/server/nginx/temp/client \
# 定义一个目录,用于存储临时文件和从代理服务器接受的数据。安装后可以使用proxy_temp_path 指令在nginx.conf配置文件中更改。默认的目录名为 profix/proxy_temp
--http-proxy-temp-path=/server/nginx/temp/proxy \
# 定义一个目录,用于存储临时文件和从 FastCGI 服务器接受的数据。安装后可以使用fastcgi_temp_path 指令在nginx.conf配置文件中更改。 默认的目录为 prefix/fastcgi_temp
--http-fastcgi-temp-path=/server/nginx/temp/fastcgi \
# 定义一个目录,用于存储临时文件和从 uwsgi 服务器接受的数据。安装后可以使用uwsgi_temp_path 指令在nginx.conf配置文件中更改。 默认的目录为 prefix/uwsgi_temp
--http-uwsgi-temp-path=/server/nginx/temp/uwsgi \
# 定义一个目录,用于存储临时文件和从 SCGI 服务器接受的数据。安装后可以使用scgi_temp_path 指令在nginx.conf配置文件中更改。 默认的目录为 prefix/scgi_temp
--http-scgi-temp-path=/server/nginx/temp/scgi \
# --build=name
# 设置一个可选的 nginx 构建名称
# --builddir=path
# 设置构建文件夹
# --with-select_module 和 --without-select_module
# 启用或禁用构建允许服务器使用 select() 方法的模块。如果平台不支持其他更合适的方法(如 kqueue、epoll 或 /dev/poll),则将自动构建该模块。
# 启用在FreeBSD和Linux上asynchronous file I/O (aio)指令的使用
--with-file-aio \
--with-pcre \
# 允许使用线程池thread pools
--with-threads \
--with-mail=dynamic \
# 启用构建SSL/TLS protocol support 模块。为流模块添加SSL/TLS协议支持。默认不构建此模块。需要OpenSSL库来构建和运行此模块。
--with-mail_ssl_module \
# 启用构建流模块 模块以进行通用的 TCP/UDP 代理和负载均衡。该模块默认不构建。
--with-stream=dynamic \
--with-stream_ssl_module
# 允许构建ngx_http_addition_module 模块,该模块能够在响应之前和之后添加文本。该模块默认不构建。
--with-http_addition_module \
# 允许构建ngx_http_auth_request_module 模块。该模块基于子请求的结果实现客户端授权。该模块默认不构建
--with-http_auth_request_module \
# 允许构建ngx_http_dav_module 模块。该模块通过WebDEV协议提供文件管理自动化。该模块默认不构建
--with-http_dav_module \
# 允许构建ngx_http_flv_module 模块。该模块为 Flash Videos (FLV) 文件提供伪流服务器端的支持。该模块默认不构建。
--with-http_flv_module \
# 允许构建ngx_http_geoip_module 模块。该模块根据客户端 IP 地址和预编译MaxMind 的数据库创建变量。该模块默认不构建。
--with-http_geoip_module=dynamic \
# 允许构建ngx_http_gunzip_module 模块。该模块使用 Content-Encoding: gzip 来解压缩响应对于那些不支持gzip编码方法的客户端。该模块默认不构建。
--with-http_gunzip_module \
--with-http_gzip_static_module \
# 允许构建ngx_http_image_filter_module 模块,该模块可以转换 JPEG, GIF, PNG, 和 WebP 格式的图片。该模块默认不构建
--with-http_image_filter_module=dynamic \
# 允许构建ngx_http_random_index_module 模块。该模块处理斜杠字符 ('/') 结尾的请求,并选择目录中的随机文件作为索引文件。该模块默认不构建。
--with-http_random_index_module \
# 允许构建ngx_http_realip_module 模块,该模块将客户端地址更改为在指定的header中发送的地址。该模块默认不构建。
--with-http_realip_module \
# 允许构建ngx_http_mp4_module 模块。该模块为 MP4 文件提供伪流服务器端的支持。该模块默认不构建。
--with-http_mp4_module \
# 允许构建ngx_http_secure_link_module 模块。该模块默认不构建。
--with-http_secure_link_module \
# 允许构建ngx_http_stub_status_module 模块。该模块提供对基本状态信息的访问。该模块默认不构建。
--with-http_stub_status_module \
# 允许构建可将 HTTPS 协议支持添加到 HTTP 服务器的模块。默认情况下,此模块参与构建。构建和运行此模块需要 OpenSSL 库支持。
--with-http_ssl_module \
# 允许构建ngx_http_slice_module 将请求拆分为子请求的模块,每个模块都返回一定范围的响应。该模块提供了更有效的大响应缓存。该模块默认不构建。
--with-http_slice_module \
# 允许构建ngx_http_sub_module 模块。该模块通过将一个指定的字符串替换为另一个来修改相应。该模块默认不构建
--with-http_sub_module \
# 允许构建一个支持HTTP/2 的模块。默认情况下,该模块不构建。
--with-http_v2_module \
--with-http_v3_module \
# 允许构建使用一个或者多个XSLT样式表转化为XML响应的ngx_http_xslt_module。该模块默认不构建。libxslt 和 libxml2 库需要这个模块来构建和启动。
--with-http_xslt_module=dynamic \
# 使用“即时编译(just-in-time compilation)”支持(1.1.12版本的 pcre_jit 指令)构建 PCRE 库。
--with-pcre-jit \
# 设置添加到 CFLAGS 变量的额外参数。
--with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-H4cN7P/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' \
--with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC'
--with-cc-opt="-I../boringssl/include" --with-ld-opt="-L../boringssl/build/ssl -L../boringssl/build/crypto"
/configure --without-http_gzip_module --with-http_addition_module
# 编译安装
make & make install
配置
shell
./configure \
--prefix=/server/nginx \
--conf-path=/server/nginx/conf/nginx.conf \
--pid-path=/server/nginx/nginx.pid \
--lock-path=/server/nginx/lock/nginx.lock \
--sbin-path=/server/nginx/sbin/nginx \
--modules-path=/server/nginx/modules \
--error-log-path=/server/nginx/logs/error.log \
--http-log-path=/server/nginx/logs/access.log \
--http-client-body-temp-path=/server/nginx/temp/client \
--http-proxy-temp-path=/server/nginx/temp/proxy \
--http-fastcgi-temp-path=/server/nginx/temp/fastcgi \
--http-uwsgi-temp-path=/server/nginx/temp/uwsgi \
--http-scgi-temp-path=/server/nginx/temp/scgi \
--with-file-aio \
--with-pcre \
--with-threads \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_geoip_module=dynamic \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module=dynamic \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_mp4_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_slice_module \
--with-http_sub_module \
--with-http_v2_module \
--with-http_v3_module \
--with-http_xslt_module=dynamic \
--with-pcre-jit
添加到系统服务
sh
# /usr/lib/systemd/system/nginx.service
[Unit]
After=network.target remote-fs.target nss-lookup.target
Documentation=https://nginx.org/en/docs/
Description=nginx-The High-performance HTTP Server
[Service]
Type=forking
PIDFile=/server/nginx/nginx.pid
ExecStartPre=/server/nginx/sbin/nginx -t -c /server/nginx/conf/nginx.conf
ExecStart=/server/nginx/sbin/nginx -c /server/nginx/conf/nginx.conf
ExecReload=/server/nginx/sbin/nginx -s reload
ExecStop=/server/nginx/sbin/nginx -s stop
ExecQuit=/server/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
增加执行权限
sh
chmod +x nginx.service