阿里云服务器ubuntu16.04源码 安装 nginx 服务器

版本

  • ubunt16.04
  • nginx-1.8.1
  • gcc-4.8.4
  • pcre-8.40
  • zlib-1.2.11
  • openssl-1.0.2n

前置环境配置

进入到 /usr/local 目录下执行下面1 2 3 4,此处路径与之后安装nginx对应

1、gcc
源码编译依赖环境

apt-get install build-essential
apt-get install libtool

// gcc --version 查看gcc版本
// gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

2、PCRE ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式

wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure  
make  
make install 

//查看pcre版本 pcre-config --version

3、zlib http://zlib.net
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip

wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz 
cd zlib-1.2.11
./configure  
make 
make install 

4、penssl https://www.openssl.org/source/
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用. 
nginx不仅支持http协议,还支持https(即在ssl协议上传输http)

wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
tar -zxvf openssl-1.0.2n.tar.gz
 

安装步骤

一、源码安装

1.下载 nginx 压缩包 

wget https://nginx.org/download/nginx-1.8.1.tar.gz

 

2.解压 nginx-1.8.1.tar.gz

tar -zxvf nginx-1.8.1.tar.gz

3.解压后 我们通过 cd 命令进入到nginx-1.8.1文件夹下面
安装nginx到 /usr/local/nginx目录下

cd nginx-1.8.1

// 配置nginx
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/pcre-8.40 \
--with-zlib=/usr/local/zlib-1.2.11 \
--with-openssl=/usr/local/openssl-1.0.2n
// 编译
make
// 安装
make install
 

如果到此为止没有报错,安装成功

启动nginx:

cd 到/usr/local/nginx

./nginx执行启动文件

输入你的服务器ip地址,会出现这样的页面

 

二、在线安装
apt-get install nginx

启动程序文件在/usr/sbin/nginx

日志放在了/var/log/nginx中,分别是access.log和error.log

并已经在/etc/init.d/下创建了启动脚本nginx

在线安装启动nginx
/etc/init.d/nginx start
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章