CentOS 7 编译安装 Nginx 1.9.7

简介: 环境说明VMware 12 中搭建的 CentOS 7 x64 4cpu 2G内存 环境中已经安装了《CentOS 7 编译安装 MySQL-5.

环境说明

VMware 12 中搭建的 CentOS 7 x64 4cpu 2G内存
环境中已经安装了《CentOS 7 编译安装 MySQL-5.7.9》《CentOS 7 编译安装PHP7

配置ip

参考《CentOS 7 编译安装 MySQL-5.7.9》中的 “配置防火墙和开放端口”

依赖库配置,编译和安装Nginx1.9.0

下载pcre-8.38.tar.gz
下载zlib-1.2.8.tar.gz
下载nginx-1.9.7.tar.gz
并上传到/root/目录

先创建一个名为nginx且没有登录权限的用户和一个名为nginx的用户组,然后安装nginx所需的依赖库和依赖包,最后通过.configure进行安装的详细配置。

#######新建nginx用户和nginx组
[root@localhost ~]# groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx
#######yum安装nginx必须的依赖库
[root@localhost ~]# yum -y install openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed

#######官网下载Nginx1.9.7的tar包,然后解压到服务器上
[root@localhost ~]# tar -zxf nginx-1.9.7.tar.gz && cd nginx-1.9.7

#######下载pcre的tar包并解压,以便支持Nginx的Rewrite功能
[root@localhost nginx-1.9.7]# tar -zxf ../pcre-8.38.tar.gz

#######下载zlib的tar包并解压,以便支持Nginx的Gzip压缩功能
[root@localhost nginx-1.9.7]# tar -zxf ../zlib-1.2.8.tar.gz

#######新建Nginx1.9.7安装时所需要的目录
[root@localhost nginx-1.9.7]# cd /var/tmp/ && mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}
[root@localhost tmp]# mkdir -p /var/run/nginx && cd ~/nginx-1.9.7

准备工作做好后,就开始正式配置Nginx-1.9.7的安装明细了。注意,在使用下面这条configure参数配置时,一定要先把反斜杠“\”后面添加的注释文字去掉!!!

[root@localhost nginx-1.9.7]# ./configure \
--prefix=/usr/share/nginx \                     [Nginx安装目录]
--sbin-path=/usr/sbin/nginx \                   [Nginx的sbin目录]
--conf-path=/etc/nginx/nginx.conf \             [Nginx的配置文件]
--error-log-path=/var/log/nginx/error.log \     [Nginx的错误日志]
--http-log-path=/var/log/nginx/access.log \     [Nginx的访问日志]
--pid-path=/var/run/nginx/nginx.pid  \          [Nginx的进程ID]
--lock-path=/var/lock/nginx.lock \
--user=nginx \                          [Nginx所属用户]
--group=nginx \                         [Nginx所属用户组]
--with-http_ssl_module \                    [Nginx的ssl模块]
--with-http_spdy_module \               [NginxGoogle spdy模块]
--with-http_dav_module \
--with-http_flv_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_random_index_module \
--with-http_degradation_module \
--with-http_secure_link_module \
--with-http_gzip_static_module \            [Nginx的gzip压缩模块]
--with-http_perl_module \
--with-pcre=pcre-8.38 \                 [pcre的安装目录]
--with-zlib=zlib-1.2.8 \                    [pcre的安装目录]
--with-debug \                          [允许DEBUG]
--with-file-aio \
--with-mail \
--with-mail_ssl_module \
--http-client-body-temp-path=/var/tmp/nginx/client_body \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-stream \                         [Nginx1.9.7特有的stream模块]
--with-ld-opt="-Wl,-E"                  [gcc的编译优化]

配置简要,如下图:

nginx1.9.7 配置简要

配置完后,就可以直接编译和安装了

最后,直接使用执行这条命令[root@localhost nginx-1.9.7]# make && make install进行安装即可。其中,make命令和make install命令的执行结果附图如下:

nginx 1.9.7 make

配置Nginx1.9.0,使之正常工作

成功安装Nginx1.9.0后,我们需要进行一些配置,包括开机启动、SSL/HTTPS服务等。其中,Nginx服务控制脚本nginx参考文章《Nginx服务启动、停止和重启等操作的SHELL脚本》,或者从github下载上传到/root/目录

#######上传Nginx服务控制脚本nginx,并赋予执行权限,删除安装包,添加Nginx服务到开机启动
[root@localhost ~]# mv ~/nginx2 /etc/init.d/nginx && chmod +x /etc/init.d/nginx
[root@localhost ~]# rm -rf nginx-1.9.7*
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig nginx on

#######测试配置是否正常
[root@localhost nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

#######新建Nginx进程日志nginx.pid目录,并启动服务
[root@localhost nginx]# mkdir -p /var/run/nginx
[root@localhost init.d]# service nginx start
Starting nginx (via systemctl):                            [  确定  ]

这里启动nginx服务时,会报“env: /etc/init.d/nginx: 没有那个文件或目录”错误,用vi命令重新创建/etc/init.d/nginx脚本就可以成功运行

最后使用命令[root@typecodes nginx]# nginx -V查看Nginx1.9.7的详细信息。
nginx 1.9.7 version

主机浏览器输入ip地址:
nginx1.9.7 welcome

常见错误参考:Nginx编译安装时常见错误分析

目录
相关文章
|
11天前
|
负载均衡 应用服务中间件 Linux
nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件,很全
这篇博客文章详细介绍了Nginx的下载、安装、配置以及使用,包括正向代理、反向代理、负载均衡、动静分离等高级功能,并通过具体实例讲解了如何进行配置。
61 4
nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件,很全
|
21天前
|
tengine 关系型数据库 MySQL
Tengine、Nginx安装MySQL数据库命令教程
本指南详细介绍了在Linux系统上安装与配置MySQL数据库的步骤。首先通过下载并安装MySQL社区版本,接着启动MySQL服务,使用`systemctl start mysqld.service`命令。若启动失败,可尝试使用`sudo /etc/init.d/mysqld start`。利用`systemctl status mysqld.service`检查MySQL的服务状态,确保其处于运行中。通过日志文件获取初始密码,使用该密码登录数据库,并按要求更改初始密码以增强安全性。随后创建一个名为`tengine`的数据库,最后验证数据库创建是否成功以及完成整个设置流程。
|
9天前
|
应用服务中间件 Linux nginx
Mac os 安装 nginx 教程(success)
这篇文章是关于如何在Mac OS系统上使用Homebrew安装nginx及其依赖,并解决安装过程中可能出现的权限问题。
22 0
Mac os 安装 nginx 教程(success)
|
21天前
|
tengine 应用服务中间件 Linux
Tengine、Nginx安装PHP命令教程
要在阿里云Linux上安装PHP,请先更新YUM源并启用PHP 8.0仓库,然后安装PHP及相关扩展。通过`php -v`命令验证安装成功后,需修改Nginx配置文件以支持PHP,并重启服务。最后,创建`phpinfo.php`文件测试安装是否成功。对于CentOS系统,还需安装EPEL源和Remi仓库,其余步骤类似。完成上述操作后,可通过浏览器访问`http://IP地址/phpinfo.php`测试安装结果。
|
14天前
|
安全 Linux 编译器
Centos 7.9如何使用源码编译安装curl最新版本
通过上述步骤,您就能在CentOS 7.9上成功地从源代码编译并安装curl的最新版本。这种方法不仅提供了灵活性,允许您定制编译选项,还确保了软件的最新功能和安全更新得到应用。
26 1
|
16天前
|
Ubuntu 搜索推荐 应用服务中间件
Nginx安装与使用
Nginx安装与使用
|
16天前
|
负载均衡 算法 应用服务中间件
Nginx安装及配置详解
Nginx安装及配置详解
|
16天前
|
应用服务中间件 程序员 开发工具
mac下安装nginx
mac下安装nginx
|
16天前
|
应用服务中间件 Linux nginx
CentOS7安装Nginx
CentOS7安装Nginx
|
16天前
|
Ubuntu Unix 应用服务中间件
Ubuntu16.04.1 安装Nginx
Ubuntu16.04.1 安装Nginx