前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >统信服务器操作系统【Nginx 编译安装】

统信服务器操作系统【Nginx 编译安装】

作者头像
Kevin song
发布2024-05-11 17:03:25
1100
发布2024-05-11 17:03:25
举报

统信服务器操作系统信息

代码语言:javascript
复制
[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用户

代码语言:javascript
复制
创建nginx用户组
groupadd nginx
创建nginx免登录用户
useradd -M -s /sbin/nologin -g nginx nginx
创建目录
mkdir  -p /var/lib/nginx/tmp/

下载Nginx源码包

代码语言:javascript
复制
wget -c http://nginx.org/download/nginx-1.22.1.tar.gz

解压源码包

代码语言:javascript
复制
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

代码语言:javascript
复制
[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并开机启动

代码语言:javascript
复制
systemctl   start  nginx   && systemctl  enable  nginx

查看nginx进程

代码语言:javascript
复制
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模块

代码语言:javascript
复制
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执行文件

代码语言:javascript
复制
./nginx -V

Nginx执行文件替换,并重启服务

代码语言:javascript
复制
备份ngixn执行文件
cp   /usr/sbin/nginx  /usr/sbin/nginx.bak
拷贝新nginx 执行文件替换旧文件
cp objs/nginx /usr/sbin/
重启nginx 服务
systemctl   restart  nginx

Nginx状态信息配置文件

代码语言:javascript
复制
location = /basic_status {
                stub_status;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }

重载配置文件

代码语言:javascript
复制
 nginx -s reload

curl 访问测试

代码语言:javascript
复制
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;

代码语言:javascript
复制
http {
....
include conf.d/*.conf;
....
}
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2024-05-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 开源搬运工宋师傅 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
轻量应用服务器
轻量应用服务器(TencentCloud Lighthouse)是新一代开箱即用、面向轻量应用场景的云服务器产品,助力中小企业和开发者便捷高效的在云端构建网站、Web应用、小程序/小游戏、游戏服、电商应用、云盘/图床和开发测试环境,相比普通云服务器更加简单易用且更贴近应用,以套餐形式整体售卖云资源并提供高带宽流量包,将热门软件打包实现一键构建应用,提供极简上云体验。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档