ubuntu16.04 安装 nginx 服务器

版权声明:版权所有,转载请注明出处。 https://blog.csdn.net/pdfcxc/article/details/84947477

版本

  • ubunt16.04
  • nginx-1.8.1
  • gcc-4.8.4
  • pcre-8.38
  • 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 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure  
make  
make install 

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
在这里插入图片描述

5.解压后 我们通过 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.38 \
--with-zlib=/usr/local/zlib-1.2.11 \
--with-openssl=/usr/local/openssl-1.0.2n
// 编译
make
// 安装
make install

至此nginx安装完成!

如果使用 nginx 访问 ftp 站点内容,需要将 nginx user设置为对应 ftp user 不然会因权限不足报 403 错误

6.启动nginx

建议使用第一种启动,否则可能会出现如下错误

nginx: [error] open() "/***/***/***/nginx.pid" failed (2: No such file or directory)
第一种

cd /usr/local/nginx

./nginx -c ./nginx.conf

第二种

/usr/local/nginx/nginx

在这里插入图片描述
重新加载配置

./nginx -s reload
1

二、在线安装

apt-get install nginx

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

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

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

在线安装启动nginx

/etc/init.d/nginx start

https://blog.csdn.net/sinat_34344123/article/details/79094003

猜你喜欢

转载自blog.csdn.net/pdfcxc/article/details/84947477