nginx安装部署

Nginx安装
用root用户安装,采用源代码编译的方式来进行安装,首先下载nginx安装要用到的所有文件(这个自行百度即可)
Nginx需要依赖下面3个包

  1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ ) zlib-1.2.8.tar.gz
  2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ ) pcre-8.21.tar.gz
  3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ ) openssl-1.0.1.tar.gz

正式开始前需要确认gcc、g++开发库已经预先安装好(如果是新安装的系统,在安装的时候选择基础安装,附加上选上开发者工具,以下会自动安装上)
检查gcc是否安装

gcc --version

检查g++是否安装

g++ --version

GCC、G++安装

联网安装
如果服务器具备联网条件,可以使用联网安装
安装gcc

yum -y install gcc

安装g++
需要注意的是安装的命令是gcc-c++而不是g++

yum -y install gcc-c++

pcre安装
执行如下命令:

  tar -zxvf pcre-8.42.tar.gz
  cd pcre-8.42/
  ./configure
  make
  make install

zlib安装
**
执行如下命令:

tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure
make
make install

openssl安装
执行如下命令:

tar -zxvf openssl-1.1.0h.tar.gz
cd openssl-1.1.0h/
./config
make
make install

nginx安装
执行如下命令:

tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0/
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.1.0h
make
make install

解释:
–prefix=/usr/local/nginx #指向nginx想要安装的目录
–with-pcre=…/pcre-8.21 #指向解压的源码目录
–with-zlib=…/zlib-1.2.8 #指向解压的源码目录
–with-openssl=…/openssl-1.0.1 #指向解压的源码目录
如果nginx要需要使用https,在执行 ./configure的时候需要加上–with-http_ssl_module --with-http_stub_status_module

测试nginx是否安装成功
nginx启动

cd /usr/local/nginx/sbin
./nginx

浏览器访问如:http://192.168.11.201/
如果能正常显示nginx首页,则表示安装成功
在这里插入图片描述
附加:
打开目录浏览功能

location / {

    autoindex on;#打开目录列表
    autoindex_exact_size off; #on显示文件的确切大小,off则会用M、G等单位
    autoindex_localtime on; #显示文件服务器时间,off显示GMT时间
    root   html;
    index  index.html index.htm;
}

Nginx编译参数解析

–prefix #nginx安装目录,默认在/usr/local/nginx
–pid-path #pid问件位置,默认在logs目录
–lock-path #lock问件位置,默认在logs目录
–with-http_ssl_module #开启HTTP SSL模块,以支持HTTPS请求。
–with-http_dav_module #开启WebDAV扩展动作模块,可为文件和目录指定权限
–with-http_flv_module #支持对FLV文件的拖动播放
–with-http_realip_module #支持显示真实来源IP地址
–with-http_gzip_static_module #预压缩文件传前检查,防止文件被重复压缩
–with-http_stub_status_module #取得一些nginx的运行状态
–with-mail #允许POP3/IMAP4/SMTP代理模块
–with-mail_ssl_module #允许POP3/IMAP/SMTP可以使用SSL/TLS
–with-pcre=../pcre-8.11 #注意是未安装的pcre路径
–with-zlib=../zlib-1.2.5 #注意是未安装的zlib路径
–with-debug #允许调试日志
–http-client-body-temp-path #客户端请求临时文件路径
–http-proxy-temp-path #设置http proxy临时文件路径
–http-fastcgi-temp-path #设置http fastcgi临时文件路径
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #设置uwsgi 临时文件路径
–http-scgi-temp-path=/var/tmp/nginx/scgi #设置scgi 临时文件路径
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值