Centos 7源码编译安装Nginx
前言
Nginx是一款轻量级的Web 服务器,其特点是,高效,开源,稳定性强,高并发(能够支持高达 50,000 个并发连接数的响应)常见的linux web服务有Linux Apche Nginx Tomcat
Nginx官网:www.nginx.org
下载nginx包
[root@Kling ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
安装依赖库
[root@Kling ~]# yum install-y gcc-c++ pcre-devel zlib-devel
创建nginx用户
[root@Kling ~]# useradd -s /sbin/nologin nginx -M(-M不创建宿主目录)
[root@Kling ~]# tail -1 /etc/passwd
nginx:x:1004:1005::/home/nginx:/sbin/nologin
解压Ngnix包
[root@Kling ~]# tar -zxvf nginx-1.18.0.tar.gz -C /usr/src (-C解压到指定目录)
安装
[root@Kling nginx-1.18.0]# ./configure --prefix= /usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
--prefix= /usr/local/nginx ——指定安装位置
--user=nginx ——运行用户
-- group=nginx ——运行用户组
--with-http_stub——状态以及模块
创建Nginx链接
[root@Kling nginx-1.18.0]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
[root@Kling nginx-1.18.0]# nginx -t ##检测
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@Kling nginx-1.18.0]#
访问一个没有的页面会看到nginx的版本号这样不安全
[root@Kling ~]# vim /usr/local/nginx/conf/nginx.conf
隐藏版本号
检查语法并重新加载配置文件
[root@Kling ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@Kling ~]# nginx -s reload
[root@Kling ~]#