Centos7 安装nginx和运行

15 篇文章 0 订阅
3 篇文章 0 订阅

1 下载Nginx

官网地址

官网 http://nginx.org/

在这里插入图片描述

下载稳定版本和之前的版本都可以,这里我下载的是nginx-1.16.1

在这里插入图片描述

CSDN地址

CSDN https://download.csdn.net/download/qq_15769939/14938603

2 上传文件到服务器

可以用ftp工具将文件上传到目录 /opt/software/ 目录不存在需自己创建

[root@localhost software]# ll
总用量 1012
-rw-r--r--. 1 root root 1032630 1月  27 13:18 nginx-1.16.1.tar.gz
[root@localhost software]#

3 安装依赖环境

3.1 安装gcc环境

[root@localhost software]# yum install gcc-c++

3.2 安装PCRE库,用于解析正则表达式

[root@localhost software]# yum install -y pcre pcre-devel

3.3 zlib压缩和解压缩依赖

[root@localhost software]# yum install -y zlib zlib-devel

3.4 SSL 安全的加密的套接字协议层,用于HTTP安全传输,也就是https

[root@localhost software]# yum install -y openssl openssl-devel

4 编译源码

4.1 解压文件

[root@localhost software]# tar -zxvf nginx-1.16.1.tar.gz

4.2 创建nginx临时目录

[root@localhost software]# mkdir /var/temp/nginx -p
[root@localhost software]# /opt/module/software/nginx-1.16.1

4.3 创建makefile文件

4.3.1 使用默认配置
[root@localhost nginx-1.16.1]# ./configure
4.3.2 自定义配置
[root@localhost nginx-1.16.1]# 
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/var/run/nginx/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
./configure \ 
命令解释
–prefix指定nginx安装目录
–pid-path指向nginx的pid
–lock-path锁定安装文件,防止被恶意篡改或误操作
–error-log错误日志
–http-log-pathhttp日志
–with-http_gzip_static_module启用gzip模块,在线实时压缩输出数据流
–http-client-body-temp-path设定客户端请求的临时目录
–http-proxy-temp-path设定http代理临时目录
–http-fastcgi-temp-path设定fastcgi临时目录
–http-uwsgi-temp-path设定uwsgi临时目录
–http-scgi-temp-path设定scgi临时目录

4.4 make 编译

[root@localhost nginx-1.16.1]# make

4.5 安装

[root@localhost nginx-1.16.1]# make install

5 管理服务

5.1 启动

[root@localhost nginx-1.16.1]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx

5.2 停止

[root@localhost sbin]# ./nginx -s stop

5.3 重新加载

[root@localhost sbin]# ./nginx -s reload
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小P聊技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值