Linux安装Nginx
注意: docker安装更便捷,这里介绍原生安装。
1.安装依赖包
所需依赖有:pcre zlib zlib-devel gcc-c++ libtool openssl openssl-devel
如果安装比较慢的话,可以切换镜像源,切换方式见如下文章https://blog.csdn.net/wdy_2099/article/details/70578529
安装命令如下:
yum -y install make pcre zlib zlib-devel gcc-c++ libtool openssl openssl-devel
2.安装Nginx
下载nginx-1.12.2.tar.gz包(下载地址 http://nginx.org/download/)可以根据实际情况下载其他版本。
2.1 首先解压:
[root@localhost nginx]# tar -xvf nginx-1.12.2.tar.gz
2.2 解压后,进入目录nginx-1.12.2,然后执行./configure 执行检查操作
开启stream块
./configure --with-stream
[root@localhost nginx]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# ./configure
2.3 最后执行编译
[root@localhost nginx-1.12.2]# make && make install
2.4 编译以后会在/usr/local下生成nginx文件夹,sbin下有启动脚本
/usr/local/nginx/sbin
[root@localhost nginx]# cd sbin/
[root@localhost sbin]# ls
nginx
3.启动Nginx
启动sbin下的nginx
[root@localhost sbin]# ./nginx
[root@localhost sbin]#
访问默认80端口:(我这边服务器地址为http://192.168.1.117:80/),出现以下界面则为启动成功:
注意:CentoS7中操作防火墙的规则外部访问需要开放对应端口
查看开放的端口号
firewall-cmd --list-all
设置开放的端口号
firewall-cmd --add-service=http –permanent
firewall-cmd --add-port=80/tcp --permanent
重启防火墙
firewall-cmd –reload