目录
1.官网yum安装稳定版本ngixn
# 安装所需依赖
yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake
yum -y install wget httpd-tools vim
# 关闭selinux ,编辑/etc/selinux/config文件 ,将SELINUX=disabled 之后将系统重启一下即可
vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
https://nginx.org/en/linux_packages.html
# 新增yum配置文件
vi /etc/yum.repos.d/nginx.repo
# 下面是文件内容,粘贴保存即可
复制下面内容 module_hotfixes=true下面会出现奇怪东西,需要删除一下
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$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/7/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
2.查看yum安装nginx的对应版本
[root@localhost sbin]# yum list | grep nginx
nginx.x86_64 1:1.24.0-1.el7.ngx @nginx-stable
nginx-debug.x86_64 1:1.8.0-1.el7.ngx nginx-stable
nginx-debuginfo.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx-module-geoip.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx-module-geoip-debuginfo.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx-module-image-filter.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx-module-image-filter-debuginfo.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx-module-njs.x86_64 1:1.24.0+0.7.12-1.el7.ngx nginx-stable
nginx-module-njs-debuginfo.x86_64 1:1.24.0+0.7.12-1.el7.ngx nginx-stable
nginx-module-perl.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx-module-perl-debuginfo.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx-module-xslt.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx-module-xslt-debuginfo.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx-nr-agent.noarch 2.0.0-12.el7.ngx nginx-stable
pcp-pmda-nginx.x86_64 4.3.2-13.el7_9 updates
3.安装nginx
sudo yum install nginx -y
4.查看nginx版本
nginx -V
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
# 查看nginx配置文件所在的位置
[root@localhost ~]# rpm -ql nginx
# 核心配置,遵循rpm包管理规范
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.24.0
/usr/share/doc/nginx-1.24.0/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
5.常用命令
# 检查配置文件语法是否正确
nginx -tc /etc/nginx/nginx.conf
# 启动
nginx /etc/nginx/nginx.conf
# 第二种启动方法
systemctl start nginx.service
# 停止
nginx -s stop-c /etc/nginx/nginx.conf
# 第二种停止方法
systemctl stop nginx.service
# 重启nginx
nginx -s reload -c /etc/nginx/nginx.conf
# 第二种重启方法
systemctl restart nginx.service
# 检查配置文件语法
nginx -t
# 重启
nginx -s reload
# 停止
nginx -s stop
# 启动
nginx