1. 编译源码安装Nginx
- nginx下载地址:http://nginx.org/en/download.html
- 本文使用:nginx-1.16.1
-
安装依赖软件
yum -y install gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
- 安装nginx
-
解压进入nginx目录
tar -zxvf nginx-1.16.1.tar.gz
-
安装nginx
[root@magic nginx-1.16.1]# ./configure [root@magic nginx-1.16.1]# make && make install
-
nginx安装到了/usr/local/nginx目录下
-
启动nginx
[root@magic ~]# /usr/local/nginx/sbin/nginx # 查看启动进程 [root@magic ~]# ps -ef | grep nginx root 7950 1 0 16:11 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx nobody 7951 7950 0 16:11 ? 00:00:00 nginx: worker process
-
访问页面
-
nginx启停命令
# 启动 /usr/local/nginx/sbin/nginx # 停止 /usr/local/nginx/sbin/nginx -s stop # 重新加载配置(热加载),并非重启服务 /usr/local/nginx/sbin/nginx -s reload
2. yum安装Nginx
官网地址:http://nginx.org/en/linux_packages.html#RHEL-CentOS
-
安装
yum-utils
sudo yum install yum-utils -y
-
创建
/etc/yum.repos.d/nginx.repo
文件[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
-
重新生成yum缓存
yum makecache fast
-
安装Nginx
# 默认安装的是nginx最新稳定版 # 如果想安装最新的快照版,执行以下命令 # sudo yum-config-manager --enable nginx-mainline # 通常我们安装稳定版 sudo yum install nginx -y
-
启停
systemctl start nginx systemctl stop nginx
-
配置文件目录:
/etc/nginx/nginx.conf
网友评论