linux安装nginx源码,CentOS7源码编译安装Nginx
一、安装步骤
1、下载 nginx 源码包 官网$ wget http://nginx.org/download/nginx-1.16.0.tar.gz
2、解压 nginx 压缩包$ tar -zxvf nginx-1.16.0.tar.gz
3、创建 www 用户 (已存在可以跳过)$ groupadd www
$ useradd -g www -s /sbin/nologin -M www
4、运行 configure 文件检测程序$ cd nginx-1.16.0
$ ./configure --prefix=/usr/local/nginx --user=www --group=www
checking for OS
+ Linux 3.10.0-957.12.2.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
# 此处是因为没有 gcc 和 gcc-c++ 依赖包,由于我是 centos 可以直接通过yum进行安装
$ yum -y install gcc gcc-c++
... 此处省略安装步奏
# 再次执行上面的 configure 步骤
$ ./configure --prefix=/usr/local/nginx --user=www --group=www
... 此处省略一部分
./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= option.
# 这次根据提示是因为没有 PCRE 库 ,执行 yum 安装 pcre-devel即可
$ yum -y install pcre-devel
... 此处省略一部分
Running transaction
正在安装 : pcre-devel-8.32-17.el7.x86_64 1/1
验证中 : pcre-devel-8.32-17.el7.x86_64 1/1
已安装:
pcre-devel.x86_64 0:8.32-17.el7
完毕!
# 再次执行 configure 步骤
$ ./configure --prefix=/usr/local/nginx --user=www --group=www
... 此处省略一部分
./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= option.
# 这此根据提示是因为没有 zlib 库 ,执行 yum 安装 zlib 和 zlib-devel 即可
$ yum -y install zlib zlib-devel
... 此处省略一部分
Running transaction
正在安装 : zlib-devel-1.2.7-18.el7.x86_64 1/1
验证中 : zlib-devel-1.2.7-18.el7.x86_64 1/1
已安装:
zlib-devel.x86_64 0:1.2.7-18.el7
完毕!
# 再次执行 configure 步骤
$ ./configure --prefix=/usr/local/nginx --user=www --group=www
... 此处省略一部分
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
# 总算通过了下面进行编译和安装
$ make && make install
# 检测是否安装成功
$ /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# 辛苦总算没有白费,成功了.
5、启动 nginx 服务$ /usr/local/nginx/sbin/nginx
# 启动了一个nginx服务,然我测试下是否启动成功
$ lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 17440 root 6u IPv4 35217 0t0 TCP *:http (LISTEN)
nginx 17441 nobody 6u IPv4 35217 0t0 TCP *:http (LISTEN)
# 完成。
# PS:如果 lsof 没有这个操作可以使用 yum -y install lsof 安装
6、配置防火墙80端口$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ systemctl restart firewalld
二、安装总结# 下载、解压 源码包
$ wget http://nginx.org/download/nginx-1.16.0.tar.gz
$ tar -zxvf nginx-1.16.0.tar.gz
# 创建 www 用户 (已存在可以跳过)
$ groupadd www
$ useradd -g www -s /sbin/nologin -M www
# 安装 前置服务
$ yum -y install gcc gcc-c++ pcre-devel zlib zlib-devel
# 检测安装环境
$ ./configure --prefix=/usr/local/nginx --user=www --group=www
# 编译 和 安装
$ make && make install
# 启动服务
$ /usr/local/nginx/sbin/nginx
# 打开防火墙
$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ systemctl restart firewalld
三、操作命令# 停止
[1]
$ pkill -9 nginx
[2]
$ nginx -s stop
# 检查配置是否正确
$ nginx -t
# 重启
$ nginx -s reload
四、配置开机自启
由于我是 CentOS 7 ,我打算用 systemctl 作为我的管理工具,下面是我的操作步骤。
还有一个原因是因为我配置 nginx 启动脚本总是报错,我懒得去弄官网给的那个脚本了。$ vim /lib/systemd/system/nginx.service
# 输入以下代码,并且保存
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
$ systemctl start nginx.service
Failed to execute operation: Access denied
# 这里报了一个错误,提示我没有权限
$ setenforce 0 # 临时关闭 selinux ,如果想长久关闭请自行搜索
$ systemctl start nginx
# 没有报错,测试一下
$ lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 1398 root 6u IPv4 19609 0t0 TCP *:http (LISTEN)
nginx 1399 www 6u IPv4 19609 0t0 TCP *:http (LISTEN)
# 成功,设置为开机自动启动
$ systemctl enable nginx.service
本文来自投稿,不代表访得立场,如若转载,请注明出处:http://www.found5.com//view/1073.html
linux安装nginx源码,CentOS7源码编译安装Nginx相关推荐
- mysql编译安装root密码_MySQL 5.7.11编译安装以及修改root密码小结
系统是CentOS 6.7 64位的,默认MySQL5.7.11下载到/usr/local/src,安装目录在/app/local/mysql目录下,MySQL数据放置目录/app/local/dat ...
- 7 centos 源码安装samba_在CentOS7.6里编译安装PHP7.4(最新版),很详细
拿到一个空的服务器,首先我们就要来用起来啦! 首先要先下载并编译安装PHP最新版本,请到php官网下载: 这里我首先在系统里在新建存储源码包的文件夹,比如我存放在这里 下载安装PHP7.4之前,你要先 ...
- Linux安装和管理程序(包括rpm包安装、卸载、升级以及源码包的手工编译安装)
点击蓝色目录查找相应内容 Linux应用程序简介 应用程序与系统命令的关系 典型应用程序的目录结构 常见的软件包封装类型 RPM包管理工具 查询RPM软件包信息 查询已安装的RPM软件信息 查询未安装 ...
- centos7编译安装mysql5.7_在Centos7源码包编译安装MySQL5.7
1.通过国内镜像下载源码包 下载包含boost的源码包 wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.23.tar.gz 2 ...
- linux bazel 源码,ubuntu 18.04编译安装bazel
bazel 是google用于构建项目的工具,主要用于构建google 的软件,如tensorflow等.我新装的ubuntu 18.04系统,bazel 用apt 安装默认只支持ubuntu14和1 ...
- mysql源码安装分析_MySQL源码分析(0):编译安装及调试(转)
编译安装 为了实现MySQL的更高级别的性能调优,我们通常需要理解其内部实现机制,并对其进行优化调试.在下面的系列中,我们会分别介绍MySQL的部分内部实现机制. 首先我们介绍如何从源代码部署一台My ...
- mysql 5.6.23 源码包安装报错_Ubuntu 14.10下编译安装MySQL 5.6.23
1. 安装环境: Ubuntu Server 14.10 MySQL-5.6.23.tar.gz 2. 安装必备的工具 sudo apt-get install make bison g++ buil ...
- 【Linux】循序渐进学运维-CentOS7使用yum方式安装nginx
文章目录 前言 测试环境 安装前准备 1. 安装前准备 2. To set up the yum repository(添加源) 安装nginx 1. 查看nginx源是否添加成功 2. 安装并查看 ...
- CentOS7.0下编译安装Nginx 1.10.0
2019独角兽企业重金招聘Python工程师标准>>> 准备工作 安装编译工具.依赖包 $ yum -y install gcc gcc-c++ autoconf automake ...
最新文章
- js 字符串转换成数字的 三种方法
- 全球首富贝佐斯离婚协议达成,前妻获383亿美元
- tableau做折线图_Tableau | 20种常用图表(上文)
- java 输出脉冲信号_一种使用SOC精确控制脉冲的方法
- Git:git-pull的用法总结
- 驱动框架8——将驱动集成到内核中
- 全局搜索关键字命令_linux全局搜索命令有哪些?
- 路网自动构建路段拓扑
- python图标中文_解决python中matplotlib中文乱码 for Mac
- 玩聚榜单-仿照Technorati的Popular频道
- python分支结构与循环结构
- 学python需要什么软件,python软件有哪些图标
- 福利篇1——嵌入式软件行业与公司汇总
- jenkins post steps设置记录
- 把一个数据库的表导入到另一个数据库中的方法
- snap vs apt
- 25款优秀的WordPress必备插件推荐
- 基于javaweb的校园机房管理平台的设计与实现(毕业设计论文+程序源码)
- 拼多多盈利模式分析研究
- linux tomcat 开发js,tomcat9-windows-服务版JS文件乱码