1,nginx安装

下面的操作是以Centos7为例

1. 使用远程连接工具连接Centos7操作系统

2.安装nginx相关依赖

(1) gcc
(2) pcre
(3) openssl
(4) zlib

2.1 安装 gcc

nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

$ yum install gcc-c++

2.2 安装 PCRE

(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:

yum install -y pcre pcre-devel

2.3安装 zlib

zlib库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

yum install -y zlib zlib-devel

2.3安装 OpenSSL

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

yum install -y openssl openssl-devel

3,安装Nginx

3.1 下载nginx,两种方式

a. 直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html
b. 使用wget命令下载(推荐)。确保系统已经安装了wget,如果没有安装,执行 yum install wget 安装。

wget -c https://nginx.org/download/nginx-1.19.0.tar.gz

3.2 解压nginx

$ tar -zxvf nginx-1.19.0.tar.gz
$ cd nginx-1.19.0

3.3 配置

其实在 nginx-1.12.0 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。

3.3.1使用默认配置

$ ./configure

3.3.2 自定义配置(不推荐)

$ ./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录

3.4 编辑安装

make && make install

3.5查看版本号

查看版本号(使用nginx操作命令前提条件:必须进入nginx的目录/usr/local/nginx/sbin.)

./nginx -v

3.6 查找安装路径:

whereis nginx

3.7 启动,停止nginx

$ cd /usr/local/nginx/sbin/
$ ./nginx                     (启动nginx)
 $ ./nginx -s stop        (停止nginx)
$ ./nginx -s quit            
 $ ./nginx -s reload        (重新加载nginx配置文件)

3.8 查询nginx进程:

ps aux|grep nginx

在这里插入图片描述

3.9 访问:192.168.100.58

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值