标签:http -- 版本信息 module nginx usr linux local
环境
centos 7
安装依赖包
yum install -y gcc gcc-c++ glibc glibc-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel \
unzip psmisc bash-completion libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed
下载源码包
mkdir /usr/local/src
cd /usr/local/src
wget http://nginx.org/download/nginx-1.20.1.tar.gz tar -xf nginx-1.20.1.tar.gz
下载nginx_upstream_check_module模块
yum install -y git cd /usr/local/src/ git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
定制版本信息
版本号、服务器类型、错误页显示
cd /usr/local/src/nginx-1.20.1
修改版本
(本例修改为myweb)
src/core/nginx.h 文件
第13行#define NGINX_VERSION
第14行#define NGINX_VER "nginx/" NGINX_VERSION
sed -i '/define NGINX_VERSION/s/1.20.1/123/' src/core/nginx.h sed -i '/^#define NGINX_VER.*NGINX_VERSION$/s/nginx/myweb/' src/core/nginx.h
修改HTTP 响应头
src/http/ngx_http_header_filter_module.c 文件
第49行 static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
sed -i '/static u_char ngx_http_server_string/s/nginx/myweb/' src/http/ngx_http_header_filter_module.c
修改错误页底部提示
src/http/ngx_http_special_response.c 文件
第36行 static u_char ngx_http_error_tail[] =
"<hr><center>nginx</center>" CRLF
sed -i '36s#nginx#myweb#' src/http/ngx_http_special_response.c
最终效果
添加nginx用户
useradd -r nginx -s /sbin/nologin
编译安装
./configure --prefix=/usr/local/nginx \
--user=nginx --group=nginx \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_gunzip_module \
--with-http_v2_module \
--with-pcre \
--with-threads \
--with-file-aio \--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=/usr/local/src/nginx_upstream_check_module
make -j 4 make install
服务及开机自启
开机启动
系统服务(systemctl)
使用systemctl管理:systemctl start | stop | reload | enable | disable nginx
/usr/lib/systemd/system/nginx.service 文件
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
使用rc.local自启
不便或不需写为服务脚本放置于/etc/rc.d/init.d/目录,且又想开机时自动运行的命令,可直接放置于/etc/rc.d/rc.local文件中
cat >>/etc/rc.d/rc.local<<EOF /usr/local/nginx/sbin/nginx EOF
添加执行权限
chmod 755 /etc/rc.d/rc.local
环境变量
使用二进制nginx管理,不用每次都写一长串的绝对路径 nginx [-s reload | stop ]
方法1:PATH变量
cat >>/etc/profile.d/nginx.sh <<EOF
export PATH=/usr/local/nginx/sbin:$PATH
EOF
soure /etc/profile.d/nginx.sh
方法2:软链接
ln -s /usr/local/nginx/sbin/nginx /usr/bin
不显示版本号
主配置文件中添加
server_tokens off;
标签:http,--,版本信息,module,nginx,usr,linux,local 来源: https://www.cnblogs.com/mmio/p/14942166.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。