官网给出了详细的不同安装方式的安装步骤(安装地址:http://nginx.org/en/linux_packages.html#RHEL-CentOS),本文采用centos安装。
按照其中的步骤信手拈来即可,下面步骤来自官网,红字为翻译
Install the prerequisites: 【安装先决条件,此处安装yum-utils工具包】
sudo yum install yum-utils
To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo
with the following contents:
【设置yum仓库源,此处为nginx的仓库源,在/etc/yum.repos.d/下创建名为nginx.repo的文件,并在该文件中做如下源配置
】
[nginx-stable] #仓库id name=nginx stable repo #仓库名字 baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ #仓库的地址 gpgcheck=1 #是否使用密钥验证,1开启,0不开启 enabled=1 #是否开启当前仓库, 1开启,0不开启 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
By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:
【默认情况下,会使用仓库中的nginx稳定版。如果你想使用最新主流的nginx版本,可运行下面的命令】
sudo yum-config-manager --enable nginx-mainline
To install nginx, run the following command:
【运行下面的命令安装nginx】
sudo yum install nginx
When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
, and if so, accept it.
【当有提示是否接受GPGkey时,接受它即可】
至此,软件安装结束。应该会出现下面提示:
Installed:
nginx.x86_64 0:1.17.9-1.el6.ngx
Complete!
那么如何查看nginx的安装目录在哪?使用下面的命令
rpm -ql nginx
[root@apollo-test yum.repos.d]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/rc.d/init.d/nginx
/etc/rc.d/init.d/nginx-debug
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.17.9
/usr/share/doc/nginx-1.17.9/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx
yum命令介绍参考:https://blog.csdn.net/coolcoffee168/article/details/105476318