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

来源:互联网 发布:网站推广优化 编辑:程序博客网 时间:2024/06/06 01:08
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


 





0 0
原创粉丝点击