1,安装nginx依赖包
yum install -y pcre-devel gcc gcc-c++ ncurses-devel perl make ncurses-devel openssl-devel zlib zlib-devel
2,官网下载nginx源码包,解压,并修改nginx版本信息
- 下载源码包:wget http://nginx.org/download/nginx-1.17.9.tar.gz
- 解压:tar –zxvf nginx-1.17.9.tar.gz
- 修改nginx版本信息:
找到该文件 vim nginx-1.17.9.tar.gz/src/core/nginx.h
#define nginx_version 1010003
#define NGINX_VERSION "1.10.3" //版本信息可以去掉
#define NGINX_VER "nginx/" NGINX_VERSION //nginx改成自己想要的
#ifdef NGX_BUILD
#define NGINX_VER_BUILD NGINX_VER " (" NGX_BUILD ")"
#else
#define NGINX_VER_BUILD NGINX_VER
#endif
#define NGINX_VAR "NGINX" //NGINX也能改成自己想要的
#define NGX_OLDPID_EXT ".oldbin"
修改nginx版本信息为的只是404错误时,页面不会出现nginx版本信息
3,编译前配置
(1) ./configure #可使用./configure --help查看相关参数用法
(2) make #开始编译
(3) make install #安装
输入该命令:./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
好了后再输入:make&&make install 进行编译安装。
4,创建软链接
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
5,nginx基本命令
nginx -t // 测试配置文件是否有语法错误
nginx // 启动
nginx -s reload // 重启
pkill -9 nginx // 强制停止
在地址栏中输入域名或ip会有提示“Welcome to nginx!”则表示安装成功。
6,错误集
(1)
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] getpwnam("nginx") failed
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
这个是因为我编译安装nginx的时候指定了–user=nginx和–group=nginx,去除就没事了
但是出于安全性考虑,还是用独立权限的账户运行(root权限太大,web渗透的时候可利用的机会太多了)
解决:useradd -s /sbin/nologin -M nginx