1、nginx安装前,必须准备工具包
C语言编译、C++编译使用
yum -y install gcc gcc-devel gcc-c++
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式
yum -y install pcre pcre-devel
ZLIB :供数据压缩用的函式库
yum -y install zlib zlib-devel
OPENSSL :在计算机网络上,OpenSSL是一个开放源代码的软件库包,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连接者的身份
yum -y install openssl openssl-devel
2、安装nginx
下载nginx安装包
wget http://nginx.org/download/nginx-1.15.8.tar.gz
解压
tar zxvf http://nginx.org/download/nginx-1.15.8.tar.gz
参数配置
解压后,在nginx-1.15.8目录下使用confiregure命令进行安装配置
./configure --prefix=/usr/local/nginx
配置参数非常多,--prefix为nginx安装的目录,这个参数非常关键,因为其他的参数,
--sbin-path=path ,
--error-log-path=path等等都会以这个prefix的路径为基准进行路径设置。
例如:我这里配置--prefix=/usr/local/nginx ,--error-log-path=logs/error.log
那么error-log-path的绝对路径就是:/usr/local/nginx/logs/error.log
可以根据自己的需要继续配置,配置参数语意解析:http://nginx.org/en/docs/configure.html
编译
make && make install
3、nginx环境变量配置
vi /etc/profile
export PATH = $PATH:/usr/local/nginx/sbin/
配置完,即时生效:source /etc/profile
4、启动nginx
nginx
nginx其他操作,操作相关参数:http://nginx.org/en/docs/switches.html
检查nginx的conf文件是否配置正确
nginx -t
重载nginx配置文件
nginx -s reload