1.下载源码包
1 | wget http://nginx.org/download/nginx-1.10.3.tar.gz |
2.安装依赖库
1 | [admin@haifly-bj-static1 ~]$ sudo yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y |
3.解压源码包
1 | [admin@haifly-bj-static1 ~]$ tar xf nginx-1.10.3.tar.gz |
4.配置对外隐藏nginx版本
1 | [admin@haifly-bj-static1 ~]$ vim src/core/nginx.h |
1 | [admin@haifly-bj-static1 ~]$ vim src/http/ngx_http_header_filter_module.c |
1 | [admin@haifly-bj-static1 ~]$ vim src/http/ngx_http_special_response.c |
5.编译安装
1 | [admin@haifly-bj-static1 nginx-1.10.3]$ ./configure --prefix=/work/admin/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module |
6.启动、停止、重启
启动
1 | [admin@haifly-bj-static1 admin]$ ./nginx/sbin/nginx |
停止
1 | [admin@haifly-bj-static1 admin]$ ./nginx/sbin/nginx -s stop |
重启
1 | [admin@haifly-bj-static1 admin]$ ./nginx/sbin/nginx -s reload |
7.配置为系统服务,开机启动
Centos 6开机启动
1 | [admin@haifly-bj-static1 ~]$ cat /etc/init.d/nginx |
添加执行权限
1 | [admin@haifly-bj-static1 ~]$ sudo chmod +x /etc/init.d/nginx |
添加为开机启动
1 | [admin@haifly-bj-static1 ~]$ sudo chkconfig --add nginx |
Centos 7开机启动
1 | [admin@haifly-bj-static1 ~]$ cat /lib/systemd/system/nginx.service |
添加为开启启动
1 | [admin@haifly-bj-static1 ~]$ sudo systemctl enable nginx |