cenos中源码方式安装nginx

nginx 源码方式安装

在cenos中通过 “源码安装” nginx,使用命令行下载、解压、安装(编译)。

1.nginx源码下载并解压

1.1 在nginx官网中复制最新版本的url地址

nginx官网下载地址

1.2 下载并解压
# 1.cd到指定目录中(随意指定目录),该目录存放安装包
cd xxx/xxx/nginx

# 2.通过命令下载安装包
wget http://nginx.org/download/nginx-1.17.8.tar.gz

# 3.解压安装包
tar -xvf nginx-1.17.8.tar.gz

在这里插入图片描述

2.源码方式安装

2.1 安装nginx

官网configure配置详细说明:http://nginx.org/en/docs/configure.html

# 1.cd到nginx源码目录中
cd /xxx/xxx/nginx/nginx-1.17.8/

# 2.执行configure。
# 作用配置nginx(安装目录,配置文件,插件等),此处配置nginx的默认安装目录、配置文件、日志文件路径。
# 可查询官网按自己需求配置
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/nginx.pid

# ssl(可选)
--with-http_stub_status_module --with-http_ssl_module

# 3.编译安装
make && make install
  • 执行configure和配置成功的回显,如果安装失败(每台机器环境不一样),请参考下面的2.2解决方案
    执行configureconfigure成功后显示

2.2 安装nginx时碰到问题查询

如果提示缺失依赖,则安装依赖后,重新执行nginx安装命令

2.2.1 执行configure命令时的错误

1.缺失PCRE library依赖

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

解决方式:

# 安装缺失依赖
yum -y install pcre-devel

2.缺失gzip依赖

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

解决方式:

# 安装缺失依赖
yum install -y zlib-devel   

3.安装ssl缺失依赖

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

解决方式:

yum -y install openssl openssl-devel

3. 项目启动及常用命令

3.1 nginx启动成功页面

在这里插入图片描述

3.2 nginx常用命令
# cd到nginx安装的目录中,此处为nginx默认安装目录
cd /usr/local/nginx/sbin

# 启动
./nginx

# 强制停止
./nginx -s stop

# 优雅停止,等待请求结束,再停止进程
./nginx -s quit

# 优雅重启
./nginx -s reload

# 检查nginx默认配置文件(/usr/local/nginx/conf/nginx.conf)
./nginx -t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值