环境
操作系统:CentOS7
服务器地址:192.168.142.101
Yum version: 3.4.3
源码安装
-
安装依赖
yum -y install gcc pcre-devel zlib-devel openssl-devel
-
下载安装包
http://nginx.org/download/ -
上传服务器并解压,解压路径为/data/soft
tar -zxvf nginx-1.19.0.tar.gz -C /data/soft
-
进入解压路径,执行configure脚本
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
-
编译及安装
make && make install
官方YUM源安装
常用的模块已经被默认指定,安装较为简单
-
配置官方的YUM源
touch /etc/yum.repos.d/nginx.repo
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
-
查看当前的yum仓库
yum repolist
-
yum安装nginx
yum install -y nginx
-
查看nginx信息
nginx -V
几个重要文件
- Nginx主配置文件
/etc/nginx/nginx.conf - Nginx配置文件
/etc/nginx/conf.d/*.conf - Nginx日志文件路径
/var/log/nginx
运行
-
检测配置文件语法是否正确
nginx -t
-
运行
systemctl start nginx
或:
systemctl reload nginx
-
检验