统信服务器操作系统信息
[root@localhost ~]# cat /etc/os-release
PRETTY_NAME="UOS Server 20"
NAME="UOS Server 20"
VERSION_ID="20"
VERSION="20"
ID=uos
HOME_URL="https://www.chinauos.com/"
BUG_REPORT_URL="https://bbs.chinauos.com/"
VERSION_CODENAME=fuyu
PLATFORM_ID="platform:uel20"
[root@localhost ~]# uosinfo
#################################################
Release: uos release 20 (fuyu)
Kernel : 5.10.0-46.uel20.x86_64
Build : UOS Server 20 (1060e) 20230606 amd64
#################################################
Nginx
Nginx是一款轻量级的开源、高性能的Web 服务器和反向代理服务器及电子邮件(IMAP/POP3)服务器。Nginx支持该可用架构部署,支持在不间断服务的情况下对软件版本进行热更新,其占用内存少、并发能力强、能支持高达 5w 个并发连接数。
编译环境依赖包
dnf install libxml2 libxml2-devel libxslt-devel gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel patch perl-ExtUtils-Embed gd-devel geoip-devel libxslt-devel libunwind-deve gperftools gperftools-devel
创建nginx用户
创建nginx用户组
groupadd nginx
创建nginx免登录用户
useradd -M -s /sbin/nologin -g nginx nginx
创建目录
mkdir -p /var/lib/nginx/tmp/
下载Nginx源码包
wget -c http://nginx.org/download/nginx-1.22.1.tar.gz
解压源码包
tar -zxvf nginx-1.22.1.tar.gz -C /opt
Nginx 编译安装
cd nginx-1.22.1/
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --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_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/UnionTech/UnionTech-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/UnionTech/UnionTech-hardened-ld -Wl,-E'
编译执行 “make -j4”命令、“make install”安装命令
systemctl管理nginx服务
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx reload
ExecStop=/usr/sbin/nginx quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
启动Nginx并开机启动
systemctl start nginx && systemctl enable nginx
查看nginx进程
ps -ef | grep nginx | grep -v "grep"
ngx_http_stub_status_module 模块
ngx_http_stub_status_module 是 Nginx 的一个标准模块,它用于输出 Nginx 的状态信息,输出状态信息可以帮助我们了解 Nginx 的运行状况,如连接数、请求处理数等。
查看是否加载ngx_http_stub_status_module模块
nginx -V 2>&1 | grep -o with-http_stub_status_module
Nginx 源码包编译
cd nginx-1.22.1/
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_stub_status_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_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/UnionTech/UnionTech-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/UnionTech/UnionTech-hardened-ld -Wl,-E'
编译执行 “make -j4”命令
禁止执行“make install”命令,避免原有nginx文件被覆盖
执行完成在objs目录下生成一个nginx执行文件
./nginx -V
Nginx执行文件替换,并重启服务
备份ngixn执行文件
cp /usr/sbin/nginx /usr/sbin/nginx.bak
拷贝新nginx 执行文件替换旧文件
cp objs/nginx /usr/sbin/
重启nginx 服务
systemctl restart nginx
Nginx状态信息配置文件
location = /basic_status {
stub_status;
allow 127.0.0.1;
allow ::1;
deny all;
}
重载配置文件
nginx -s reload
curl 访问测试
curl -L 127.0.0.1/basic_status
Nginx 配置文件模块介绍
Nginx 多配置文件配置
Nginx配置文件中支持包含多个配置文件,可在虚拟主机的配置将使用,在程序加载运行时候首先会读取nginx.conf 的配置文件,然后再读取 /etc/nginx/conf.d/下面的配置文件;
在/etc/nginx/nginx.conf文件中,设置include /etc/nginx/conf.d/*.conf;
http {
....
include conf.d/*.conf;
....
}