1.概述
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好。
2.官网
3.下载
nginx: downloadhttps://nginx.org/en/download.html
4.linux下安装
4.1 安装pcre
这个可以一键下载下面四个
yum -y install gcc zlib-devel pcre-devel openssl openssl-devel
解压
tar -zxvf pcre-8.13.tar.gz
进入目录
cd pcre-8.13
./configration
如果安装了c++的环境就可跳过,如未安装:yum install gcc-c++ (点击y即可)
编译
make
make intall
4.2 安装openssl
tar -zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./configration
make
make install
4.3 安装zlib
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
4.4 安装nginx:
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure && make && make install
5.启动nginx
1.通过进程id或者搜索获取当前nginx运行的路径
ll /proc/4562/exe或者find / -name nginx
2.使用-t获取配置文件路径
/usr/local/nginx/sbin/nginx -t
3.常用命令
如果需要使用nginx命令必须进入目录,上面有如何查找目录
cd /usr/local/nginx/sbin
查看nginx版本号
./nginx -v
启动ngixn
./nginx
关闭nginx
./nginx -s stop
重新加载nginx
./nginx -s reload
4.开放端口
为了以后方便使用,可以开放端口或者关闭防火墙,建议开放端口
查看开放的端口
firewall-cmd --list-all
设置开放端口
firewall-cmd --add-service=http -permanent
sudo firewall-cmd --add -port=80/tcp --permanend
重启防火墙
firewall-cmd -reload