nginx安装

1、初始化系统

查看系统版本

[root@RHEL7-1 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.4 (Maipo)
[root@RHEL7-1 ~]#

检查防火墙状态,关闭开机自启动

[root@RHEL7-1 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@RHEL7-1 ~]# systemctl disable firewalld

安装默认组件

[root@RHEL7-1 ~]# yum install gcc gcc-c++ autoconf pcre pcre-devel make wget httpd-tools vim tree

查看selinux状态

[root@RHEL7-1 ~]# getenforce
Disabled

临时关闭selinux

[root@localhost ~]# setenforce 0

永久关闭selinux
​ 1、打开配置文件

[root@RHEL7-1 ~]# vim /etc/selinux/config

​ 2、修改配置参数

SELINUX=disabled
SELINUXTYPE=targeted
2、安装nginx

创建相应目录结构并查看

[root@RHEL7-1 ~]# mkdir /soft/{code,logs,package/src} -p
[root@RHEL7-1 ~]# tree /soft
/soft
├── code
├── logs
└── package
    └── src

4 directories, 0 files
[root@RHEL7-1 ~]# 

获取nginx最新yum源配置
1、访问nginx官网http://nginx.org/

image.png

image.png

image.png

2、查看到相应的操作手册
image.png

安装yum-utils

[root@RHEL7-1 ~]# yum install yum-utils
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 yum-utils-1.1.31-42.el7.noarch 已安装并且是最新版本
无须任何处理
[root@RHEL7-1 ~]# 

增加yum源文件
1、新增一个repo文件

[root@RHEL7-1 ~]# vim /etc/yum.repos.d/nginx.repo

2、加入如下配置

[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

[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

安装最新稳定版

yum install nginx

安装开发版

yum-config-manager --enable nginx-mainline

ps:nginx三大分类:
Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
Stable version:最新稳定版,生产环境上建议使用的版本
Legacy versions:遗留的老版本的稳定版
查看nginx安装信息

[root@RHEL7-1 ~]# rpm -q nginx
nginx-1.16.1-1.el7.ngx.x86_64
[root@RHEL7-1 ~]# 

查看nginx编译参数

[root@RHEL7-1 ~]# nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (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'
[root@RHEL7-1 ~]# 

查看nginx安装软件包

[root@RHEL7-1 ~]# 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/sysconfig/nginx
/etc/sysconfig/nginx-debug
/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.16.1
/usr/share/doc/nginx-1.16.1/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

查看nginx相关配置文件

[root@RHEL7-1 ~]# rpm -qc nginx
/etc/logrotate.d/nginx
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
[root@RHEL7-1 ~]# 

nginx启动

[root@RHEL7-1 ~]# nginx

注意,用该方法启动nginx时,systemctl status nginx会显示nginx未启动(实际上已经启动)
查看nginx启动状态

[root@RHEL7-1 ~]# nginx
[root@RHEL7-1 ~]# ps -ef | grep nginx
root       9906      1  0 19:44 ?        00:00:00 nginx: master process nginx
nginx      9907   9906  0 19:44 ?        00:00:00 nginx: worker process
root       9911   1213  0 19:44 pts/0    00:00:00 grep --color=auto nginx
[root@RHEL7-1 ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: http://nginx.org/en/docs/

9月 03 19:42:43 RHEL7-1 systemd[1]: Starting nginx - high performance web server...
9月 03 19:42:43 RHEL7-1 systemd[1]: PID file /var/run/nginx.pid not readable (yet?) after start.
9月 03 19:42:43 RHEL7-1 systemd[1]: Started nginx - high performance web server.
9月 03 19:43:01 RHEL7-1 systemd[1]: Stopping nginx - high performance web server...
9月 03 19:43:01 RHEL7-1 systemd[1]: Stopped nginx - high performance web server.
[root@RHEL7-1 ~]# 

你可能感兴趣的:(nginx安装)