源码编译安装nginx

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值