一、Nginx
1、Nginx是一个高性能的 HTTP 和 反向代理 服务,也是一个IMAP/POP3/SMTP服务。
2、Nginx是一款轻量级(对环境的依赖性比较小,可以在任何操作系统上运行的) web服务器/反向代理服务器及电子邮件代理服务器。其特点是:占有内存少,并发能力强。
二、yum安装
1、配置nginx的yum源
[root@mike ~]# cd /etc/yum.repos.d/
[root@mike yum.repos.d]# vim nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
[root@mike yum.repos.d]# yum -y install nginx
[root@mike yum.repos.d]# nginx -v #查看版本号
nginx version: nginx/1.16.1
[root@mike yum.repos.d]# nginx -V #查看版本且查看详细加载模块
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local
/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
关闭防火墙和selinux
[root@mike~]# getenforce
Enforcing
[root@mike ~]# setenforce 0
[root@mike ~]# systemctl stop firewalld
[root@mike ~]# systemctl disable firewalld
[root@mike ~]# systemctl start nginx
三、源码安装
1、安装编译环境
[root@mike ~]# yum -y install gcc gcc-c++
2、安装pcre软件包(使nginx支持http rewrite模块)
[root@mike ~]# yum install -y pcre pcre-devel
3、安装openssl-devel(使nginx支持ssl)
[root@mike ~]# yum install -y openssl openssl-devel
4、安装zlib
[root@mike ~]# yum install -y zlib zlib-devel
5、创建用户nginx
[root@mike ~]# useradd nginx
6、安装
[root@mike ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
[root@mike ~]# tar xzf nginx-1.16.1.tar.gz -C /usr/local/
[root@mike ~]# cd /usr/local/nginx-1.16.1/
[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
[root@mike nginx-1.16.1]# make && make install
7、通过nginx控制服务
1、编译安装的时候,需要进行软链接
[root@proxy-nginx ~]# ln -s /usr/loacl/nginx/sbin/nginx /usr/local/sbin
nginx -c /path/nginx.conf # 以特定目录下的配置文件启动nginx:
nginx -s reload # 修改配置后重新加载生效
nginx -s stop # 快速停止nginx
nginx -t # 测试当前配置文件是否正确
nginx -t -c /path/to/nginx.conf # 测试特定的nginx配置文件是否正确
其中nginx -t nginx -s reload
比较常用