原文地址>>https://blog.7core.cn/thread-18.htm
本文已经简化仅含命令,相关注释请查看原文(非常详细)
>> 本次实验环境
- 系统:Centos7.5(1804)、软件:Nginx 1.15.5、依赖:Pcre8.42、Zlib-1.2.11、Openssl-1.1.1
1、创建用户及用户组
[root@7Core ~]#groupadd -r nginx
[root@7Core ~]# useradd -r -g nginx -s /sbin/nologin -d /usr/local/nginx -M nginx
2、创建相关目录
[root@7Core ~]# mkdir -pv /var/tmp/nginx/{client_body,proxy,fastcgi,uwsgi,scgi}
[root@7Core ~]# chown -R nginx:nginx /var/tmp/nginx/
[root@7Core ~]# mkdir -pv /usr/local/nginx/logs
[root@7Core ~]# chown -R nginx:nginx /usr/local/nginx/
3、安装基本环境
[root@7Core ~]# yum -y install gcc gcc-c++ autoconf automake make wget vim
[root@7Core ~]# yum -y install openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed libtool zlib zlib-devel pcre pcre-devel patch
4、创建临时软件包目录
[root@7Core ~]# mkdir package && cd package
5、安装PCRE-8.42(Nginx的Rewrite功能)
[root@7Core package]# wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
[root@7Core package]# tar -zxvf pcre-8.42.tar.gz
[root@7Core package]#cd pcre-8.42/ && ./configure && make && make install && cd ..
6、安装Zlib-1.2.11(Nginx的Gzip压缩功能)
[root@7Core package]# wget http://www.zlib.net/fossils/zlib-1.2.11.tar.gz
[root@7Core package]# tar -zxvf zlib-1.2.11.tar.gz
[root@7Core package]# cd zlib-1.2.11 && ./configure && make && make install && cd ..
7、安装OpenSSL-1.1.1(nginx第三方模块—nginx-sticky-module的使用)
[root@7Core package]# wget https://www.openssl.org/source/openssl-1.1.1-pre8.tar.gz
[root@7Core package]# tar -zxvf openssl-1.1.1-pre8.tar.gz
[root@7Core package]# cd openssl-1.1.1-pre8 && ./config && make && make install && cd ..
8、安装nginx-sticky-module
[root@7Core package]# wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz
[root@7Core package]# tar -zxvf master.tar.gz
[root@7Core package]# mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ nginx-sticky-module/
9、安装Nginx-1.15.5
[root@7Core package]# wget http://nginx.org/download/nginx-1.15.5.tar.gz
[root@7Core package]# tar -zxvf nginx-1.15.5.tar.gz
[root@7Core package]# cd nginx-1.15.5
[root@7Core nginx-1.15.5]# ./configure \
--prefix=/usr/local/nginx\
--sbin-path=/usr/sbin/nginx\
--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/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_random_index_module \
--with-http_degradation_module \
--with-http_secure_link_module \
--with-http_gzip_static_module \
--with-http_perl_module \
--add-module=../nginx-sticky-module\
--with-pcre=../pcre-8.42 \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.1.1-pre8 \
--with-file-aio \
--with-mail \
--with-mail_ssl_module \
--http-client-body-temp-path=/var/tmp/nginx/client_body\
--http-proxy-temp-path=/var/tmp/nginx/proxy\
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi\
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\
--http-scgi-temp-path=/var/tmp/nginx/scgi\
--with-stream \
--with-ld-opt="-Wl,-E"
10、配置完成后编译并安装Nginx
[root@7Core nginx-1.15.5]# make && make install
11、将Nginx加入systemctl管理服务
[root@7Core nginx-1.15.5]# vim /usr/lib/systemd/system/nginx.service
#按i进入编辑模式写入以下内容(不包含本行)
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/sbin/nginx-c /etc/nginx/nginx.conf
ExecReload=/usr/sbin/nginx-s reload
ExecStop=/usr/sbin/nginx-s stop
[Install]
WantedBy=multi-user.target
12、给予文件754权限
[root@7Core nginx-1.15.5]# chmod 754 /usr/lib/systemd/system/nginx.service
13、修改或新增文件需要执行以下语句才能生效
[root@7Core nginx-1.15.5]# systemctl daemon-reload
14、启动Nginx服务器
[root@7Core nginx-1.15.5]# systemctl start nginx
[root@7Core nginx-1.15.5]# systemctl enable nginx
15、查看Nginx服务启动状态
[root@7Core nginx-1.15.5]# systemctl status nginx
16、CentOS7 添加开放TCP 80端口
[root@7Core nginx-1.15.5]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@7Core nginx-1.15.5]# firewall-cmd --reload
17、查看Nginx版本
[root@7Core nginx-1.15.5]# nginx -v
>>返回结果如下图,即安装成功
网友评论