nginx主要有三种版本:Mainline version\Stable version\Legacy versions,在生产环境最好使用Stable版本(稳定版),如图所示
下载地址: http://nginx.org/en/download.html
先安装依赖项:
yum -y install pcre*
yum -y install openssl*
手动下载并传入Linux里nginx安装包,或者用wget 命令下载:
wget http://nginx.org/download/nginx-1.16.1.tar.gz
注:文档编写时最新版本是nginx-1.16.1.tar.gz
解压tar包到 /usr/local 目录
tar -xvf nginx-1.16.1.tar.gz -C /usr/local
cd /usr/local/nginx-1.16.1/
安装模块(四行是一句),nginx 1.9.5及以后版本执行如下
./configure --prefix=/usr/local/nginx-1.16.1/ \
--conf-path=/usr/local/nginx-1.16.1/nginx.conf \
--with-http_ssl_module --with-http_v2_module \
--with-http_stub_status_module --with-pcre
如果你安装的是nginx 1.9.5 以前的版本执行如下:
./configure --prefix=/usr/local/nginx-1.16.1/ \
--conf-path=/usr/local/nginx-1.16.1/nginx.conf \
--with-http_ssl_module --with-http_spdy_module \
--with-http_stub_status_module --with-pcre
注:nginx 1.9.5 已经没有了 --with-http_spdy_module ,取代的是 --with-http_v2_module
命令解析:
#编译后存放的目录
./configure --prefix=/usr/local/nginx-1.16.1/
#配置文件的路径,如果不指定则在/usr/local/nginx-1.16.1/conf/ nginx.conf
--conf-path=/usr/local/nginx-1.16.1/nginx.conf
#指明需要一起安装的Nginx模块
--with-http_ssl_module --with-http_spdy_module \
--with-http_stub_status_module --with-pcre
执行编译语句:
make && make install
nginx常用命令:
/usr/local/nginx-1.16.1/sbin/nginx #启动
/usr/local/nginx-1.16.1/sbin/nginx -s reload #重启
/usr/local/nginx-1.16.1/sbin/nginx -s stop #停止
/usr/local/nginx-1.16.1/sbin/nginx -t #验证
/usr/local/nginx-1.16.1/sbin/nginx -v #查看nginx版本
配置开机nginx自启动,编辑/etc/rc.local文件
vi /etc/rc.local
/usr/local/nginx-1.16.1/sbin/nginx
将rc.local修改为可执行
chmod 777 /etc/rc.d/rc.local