001.1 Linux下安装Nginx并设开机自启

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值