1. 登录nginx官网下载nginx安装包
nginx包下载地址:Index of /download/
选中要安装的版本下载或者右击复制下载链接
登录服务器下载tar包:wget https://nginx.org/download/nginx-1.7.2.tar.gz
2. 解压tar包
tar -zxvf nginx-1.7.2.tar.gz
将解压后的文件夹移动到自己指定的目录
mv nginx-1.7.2 /usr/local/nginx
cd /usr/local/nginx
3. 检查及安装依赖
cd /nginx-1.7.2
使用命令 ./configure 检查配置,如果报以下提示
则需要安装依赖包:
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
4. 编译&安装
make
make install
5. 开启防火墙
systemctl start firewalld
6. 设置防火墙白名单
firewall-cmd --zone=public --add-port=80/tcp
7. 启动nginx
cd /usr/local/nginx/sbin
sbin下有个nginx脚本,执行nginx脚本
./nginx
8. 修改环境变量,以便任何地方都可以使用nginx命令
vim /etc/profile
在末尾添加
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
重新加载环境变量
source /etc/profile
9. 停止/重启nginx
停止: nginx -s stop
重启:nginx -s reload