一、首先安装必要的库nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库。选定/usr/local为安装目录,以下具体版本号根据实际改变。1.安装PCRE库$ cd /usr/local/$ wget ftp://ftp...
一、首先安装必要的库
nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库。选定/usr/local为安装目录,以下具体版本号根据实际改变。
1.安装PCRE库
$ cd /usr/local/
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
$ tar -zxvf pcre-8.36.tar.gz
$ cd pcre-8.36
$ ./configure
$ make
$ make install
2.安装zlib库
$ cd /usr/local/
$ wget http://zlib.net/zlib-1.2.8.tar.gz
$ tar -zxvf zlib-1.2.8.tar.gz
$ cd zlib-1.2.8
$ ./configure
$ make
$ make install
3.安装ssl
$ cd /usr/local/
$ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
$ tar -zxvf openssl-1.0.1j.tar.gz
$ ./config
$ make
$ make install
二、安装nginx
$ cd /usr/local/
$ wget http://nginx.org/download/nginx-1.12.2.tar.gz
$ tar -zxvf nginx-1.12.2.tar.gz
$ cd nginx-1.12.2
$ ./configure --prefix=/usr/local/nginx
$ make
$ make install
在--prefix后面接以下命令:
--with-pcre=/usr/local/pcre-8.36 指的是pcre-8.36 的源码路径。
--with-zlib=/usr/local/zlib-1.2.8 指的是zlib-1.2.8 的源码路径。
三、shell安装脚本
脚本中可以选定版本号,支持库包是以yum方式在线安装的#!/bin/bash #-------------------------------------------------------- # Function: Install nginx for CentOS7 # Date: 2018-1-06 # Author: Anwar Wong #-------------------------------------------------------- #Print debug information ? NGINX_VER="$?" NGINX_SOFT="nginx-${NGINX_VER}.tar.gz" NGINX_URL="http://nginx.org/download" NGINX_DIR="/usr/local/nginx" NGINX_SRC=`echo $NGINX_SOFT| sed 's/.tar.*//g'` NGINX_YUM="yum install -y" NGINX_ARG="--user=www --group=www --with-http_stub_status_module --with-http_ssl_module" ? ? if [$? -eq 0]; then echo -e "\033[32m-----------------\033[0m" echo -e "\033[32mUsage:{/bin/bash $0 1.2.3|1.12.2}\033[0m" exit 0 fi #Installing dependencies $NGINX_YUM wget make tar gcc gcc-c++ glibc zlib zlib-devel $NGINX_YUM perl perl-devel pcre pcre-devel openssl openssl-devel ? #Downloading wget -c $NGINX_URL/$NGINX_SOFT tar -xzf $NGINX_SOFT cd $NGINX_SRC ? #Creating user and group useradd -s /sbin/nologin www ? #Starting install nginx ./configure --prefix=$NGINX_DIR/$NGINX_ARG ? #Compile nginx make -j4 make -j4 install ? #Starting Nginx $NGINX_DIR/sbin/nginx ? #Show nginx status ps -ef |grep nginx netstat -tnlp |grep nginx 四、启动 $ /usr/local/nginx/sbin/nginx 检查是否启动成功: 打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。 部分命令如下: 重启: $ /usr/local/nginx/sbin/nginx –s reload 停止: $ /usr/local/nginx/sbin/nginx –s stop 测试配置文件是否正常: $ /usr/local/nginx/sbin/nginx –t 强制关闭: $ pkill nginx ? -----------未完待续-------------
编程基础网
本文标题为:Centos下Nginx源码安装与配置并附shell编程实现自动化安装
基础教程推荐
猜你喜欢
- win10搭建配置ftp服务器的方法 2022-11-12
- Apache Spark源码走读之15 -- Standalone部署模式下的容错性分析 2023-09-28
- 利用Apache部署静态网站(一) 2023-09-09
- centos7 nginx配置ssl证书实现https访问同时http访问 2023-09-22
- centos 7智熄直接断电导致无法启动 2023-09-23
- apache 环境下 php 的配置注意事项 2022-09-01
- Docker镜像与容器的导入导出以及常用命令总结 2022-11-24
- apache+tomcat实现session共享 2023-09-08
- Apache索引目录浏览的学习笔记 2023-09-28
- Centos7 nginx启动脚本 2023-09-22
