Linux环境下如何安装Nginx
1.上传Nginx的tar包
首先需要下载Linux系统版本的Nginx安装包,可以从Nginx官网上进行相应版本下载,也可以通过分享的云盘链接下载:链接:链接:https://pan.baidu.com/s/13Gw_NVLTLXXa4mA4EexRdA
提取码:ihkc
链接对应1.8.0版本的Nginx,链接失效或有需要更高版本可私信联系。
2.安装Nginx的依赖
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
3.创建nginx安装路径
mkdir /usr/local/nginx
3.解压nginx
tar -xvf nginx-1.8.0.tar.gz -C /usr/local/nginx
/**
* 1.在nginx所在的压缩tar包所在的文件夹下运行该命令
* 2."nginx-1.8.0.tar.gz"是nginx的压缩包的名字
*/
4.编译nginx
4.1.进入nginx的文件目录
cd /usr/local/nginx/nginx-1.8.0
4.2.编译nginx
./configure
make
make install
5.开放nginx的80端口
5.1.开放80端口
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
5.2.开放的端口永久保存到防火墙
/etc/rc.d/init.d/iptables save
6.运行nginx
6.1.进入nginx的运行目录
cd /usr/local/nginx/sbin
6.2.运行nginx
./nginx
6.3.关闭
./nginx -s stop
6.4.重启
./nginx -s reload
7.常见问题
7.1 缺少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=option.
解决方法:sudo apt-get install libpcre3 libpcre3-dev
7.2 缺少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=option.
解决方法:sudo apt-get install zlib1g-dev
7.3 apt-get命令被占用
Could not get lock /var/lib/dpkg/lock - open (11: Resource
temporarily unavailable) Unable to lock the administration
directory (/var/lib/dpkg/), is another process using it?
解决方法:找到占用进程,然后kill