linux下nginx编译安装、版本信息修改
环境
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;
linux下nginx编译安装、版本信息修改的更多相关文章
- Linux下nginx编译安装教程和编译参数详解
这篇文章主要介绍了Linux下nginx编译安装教程和编译参数详解,需要的朋友可以参考下 一.必要软件准备1.安装pcre 为了支持rewrite功能,我们需要安装pcre 复制代码代码如下: # y ...
- Linux 下Nginx编译安装
Untitled .note-content {font-family: 'Helvetica Neue', Arial, 'Hiragino Sans GB', STHeiti, 'Microsof ...
- centOS linux 下nginx编译安装详解
Nginx的官方网站是 www.nginx.org Nginx的下载地址是:http://nginx.org/en/download.html 由 于官网的设计非常简洁不大气不上档次,所以我们 ...
- linux下nginx编译安装
步骤: 1.获取nginx安装包. 进入nginx官网:http://nginx.org/ 找到稳定版本: 点击红框内的链接. 使用wget获取安装包. wget http://nginx.org/d ...
- Linux下Nginx的安装(二)
一.安装Nginx ## 安装前准备 ## #GNU编译器集合 #Nginx编译需要PCRE #在Nginx的各种模块中需要使用gzip压缩 #在Nginx中,如果服务器提供安全网页时则会用到Open ...
- Nginx 1.9.7.2 + PHP 5.6.18(FastCGI)在CentOS Linux下的编译安装
本文参考张宴的Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)[原创]完成.所有操作命令都在CentOS 6.x 64位操作系统下实践 ...
- Linux下Nginx的安装、升级及动态添加模块
系统基于ubuntu server 14.04.4 amd64 安装 第一步 下载并解压Nginx压缩包 从Nginx官网下载Nginx,或者在Linux上执行wget http://nginx.or ...
- linux下nginx的安装和配置
准备目录 [root@sqh ~]# mkdir /usr/local/nginx [root@sqh ~]# cd /usr/local/nginx 添加一些支持和依赖 1.安装gcc 安装redi ...
- Linux下Nginx的安装与配置
安装前需要安装pcre:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/1.解压缩: tar xjpf pcre-7.8.tar.b ...
随机推荐
- mysql批量新增的语法
?useUnicode=true//语序编码反射光hi &characterEncoding=UTF-8//字符 &autoReconnect=true//自动连接 &useA ...
- js调试之firbug
说下几种方法吧: 1.用alert 这个最最直观 把你想要的内容弹出来给你看,但是要看哪里 就要在哪里加,比较麻烦 2.用firefox 或者chrome浏览器 里面有debug工具的 3.如果想用i ...
- JAVA 之 每日一记 之 算法( 给定一个正整数,返回它在 Excel 表中相对应的列名称。 )
题目: 给定一个正整数,返回它在 Excel 表中相对应的列名称. 例如: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -& ...
- 什么是云效持续集成?如何关联Jenkins进行持续集成?
什么是云效持续集成?如何关联Jenkins进行持续集成?云效流水线 Flow是一款企业级.自动化的研发交付流水线, 提供灵活易用的持续集成.持续验证. 持续发布功能,帮助企业高质量.高效率的交付业务. ...
- container of()函数简介
在linux 内核编程中,会经常见到一个宏函数container_of(ptr,type,member), 但是当你通过追踪源码时,像我们这样的一般人就会绝望了(这一堆都是什么呀? 函数还可以这样定义 ...
- shell脚本获取文件名、路径名、文件类型
1. 从字符串获取指定内容 从字符串中提取特定的信息,常用于获取文件名.文件类型.所在路径等. 1.1 获取字符串信息 用指定的方式(PATTERN)从字符串(PARAMETERS)中移除内容 &qu ...
- vs code使用git---http方式
1.从git上复制http路径 2.在vs code的工作区新建文件夹 3.选择添加远程储存库 4.输入复制的git路径然后命名远程储存库名称 5.选择从所有远程储存库中拉取分支 6.选择分支,切 ...
- Vue3 父组件调用子组件的方法
Vue3 父组件调用子组件的方法 // 父组件 <template> <div> 父页面 <son-com ref="sonRef"/> < ...
- 深入学习PHP中的JSON相关函数
在我们当年刚刚上班的那个年代,还全是 XML 的天下,但现在 JSON 数据格式已经是各种应用传输的事实标准了.最近几年开始学习编程开发的同学可能都完全没有接触过使用 XML 来进行数据传输.当然,时 ...
- mysql5.7执行sql语句提示Expression #1 of ORDER BY clause is not in GROUP BY
mysql 新版本出现group by 语句不兼容问题 [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause ...