下载安装
环境
使用Centos7作为Nginx安装环境
Nginx版本下载
nginx-1.15.8 作为本次安装版本
# wget下载安装包
wget http://nginx.org/download/nginx-1.15.8.tar.gz
# mwget下载安装包
mwget http://nginx.org/download/nginx-1.15.8.tar.gz
安装前环境配置
安装 make: yum -y install autoconf automake make
安装 g++: yum -y install gcc gcc-c++
# 一般系统中已经装了了 make 和 g++, 无须再装
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum install -y openssl openssl-devel
安装
# 解压压缩包
tar -zxvf nginx-1.15.8.tar.gz
# 进入目录
cd nginx-1.15.8
# 编译及安装
./configure --prefix=/opt/myapp/nginx/app-ngxin/1-nginx --with-http_stub_status_module
--with-http_ssl_module
make
make install
安装成功
配置环境变量
# 编辑环境变量文件
vim /etc/profile
# 添加环境变量
export PATH=$PATH:/opt/myapp/nginx/app-ngxin/1-nginx/sbin
# 重载配置文件
source /etc/profile
查看配置成功
启动
# 启动
nginx
# 查看启动成功
ps -ef|grep nginx
浏览器访问
80端口问题
# 查看防火墙开放端口
firewall-cmd --zone=public --list-ports
# 开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 关闭80端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent
# 配置生效
firewall-cmd --reload
常用命令
# 启动
nginx
# 重启
ngxin -s reload
# 停止
nginx -s stop
# 退出
nginx -s quit