1.下载安装包
//安装网络仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
[root@localhost yum.repos.d]# yum clean all && yum makecache
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
nginx-1.10.2.tar.gz
2.解压、创建用户、日志目录
[root@localhost src]# tar xf nginx-1.10.2.tar.gz -C /usr/local/
[root@localhost src]# tar xf nginx-1.10.2.tar.gz -C /usr/local/
[root@localhost src]# useradd -r -M -s /sbin/nologin nginx
[root@localhost src]# mkdir -p /var/log/nginx
[root@localhost src]# chown -R nginx.nginx /var/log/nginx
3. 下载依赖包、编译安装
[root@localhost ~]# cd /usr/local/nginx-1.10.2/
[root@localhost nginx-1.10.2]# yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
[root@localhost nginx-1.10.2]# ./configure \
--prefix=/usr/local/nginx/ \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_sub_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.10.2]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
4. 启动nginx
//创建环境变量
[root@localhost nginx-1.10.2]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost nginx-1.10.2]# source /etc/profile.d/nginx.sh
[root@localhost nginx-1.10.2]# nginx
//查看端口号
[root@localhost nginx-1.10.2]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 70 [::]:33060 [::]:*
LISTEN 0 128 [::]:3306 [::]:*