Nginx的下载、安装、启动|重启|关闭-虚拟机下操作

1、下载nginx
下载地址为:http://nginx.org/download/nginx-1.10.1.tar.gz
进入linux命令行模式,使用下面命令将nginx下载到 /usr/local/src/目录下面
cd /usr/local/src/
wget  http://nginx.org/download/nginx-1.10.1.tar.gz
如图

下面进行nginx的解压和安装,使用如下命令进行操作
2、解压nginx压缩包
tar zxvf  nginx-1.10.1.tar.gz
如图


3、安装nginx
先进入nginx-1.10.1文件夹
cd nginx-1.10.1/
执行命令,将nginx安装到 /usr/local/nginx目录下
./configure --prefix=/usr/local/nginx
注意:
nginx的安装过程中,nginx的rewrite依赖PCRE库的还有也有依赖zlib的,所以需要在./configure之前需要安装pcre和zlib,命令如下:
yum install pcre
yum install zlib
如果已经安装还出现了提示未安装的情况,则需要安装devel
yum install pcre-devel
yum install zlib-devel
缺少这个两个库的错误信息如下:
缺少PCRE
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
缺少zlib
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
也有出现缺少openssl的情况,可以自己安装,方法和pcre安装一样。
这里文档中的方法是使用yum安装,需要有联网模式,如果不能访问公网,则自己到外网下载库,然后编译安装.

4、启动、重启、关闭nginx
nginx默认的端口是80端口,但是linux的80端口是可能被其他程序或者系统本身占用的,还有本案例使用的root的用户,一般真正项目中不会使用root用户,linux系统是不允许非root用户使用1000以前的端口的。
可以先查看下80端口是否被占用,命令如下:
netstat -antp


从图中发现80端口未被占用,如果被占用,可以直接将其pid使用kill -9 pid将其杀死
启动nginx
先进入 /usr/local/nginx/sbin目录下,输入./nginx命令启动nginx
cd /usr/local/nginx/sbin
./nginx
只要没有其他的提示就启动成功了,然后测试是否启动成功
在物理机的浏览器上面输入虚拟机的ip,能够得到如下nginx的欢迎页面,如果无法访问请检查linux防火墙是否关闭


关闭nginx
./nginx -s stop
重启nginx
./nginx -s reload


 





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值