CentOS 软件安装之Nginx源码安装

简介: step1.首先wget下载源码包鼠标右击复制链接地址Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版Stable version:最新稳定版,生产环境上建议使用的版本Legacy versions:遗留的老版本的稳定版# wget http://nginx.
step1.首先wget下载源码包

鼠标右击复制链接地址

img_38a98fd92c1b7bf80251c39ef5175834.png
Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
Stable version:最新稳定版,生产环境上建议使用的版本
Legacy versions:遗留的老版本的稳定版
# wget http://nginx.org/download/nginx-1.14.0.tar.gz
step2.解压nginx-1.14.0.tar.gz包
# tar -zxvf nginx-1.14.0.tar.gz
step3.进入解压的文件夹安装nginx
[root@localhost soft_tar]# ls
nginx-1.14.0  nginx-1.14.0.tar.gz
[root@localhost soft_tar]# cd nginx-1.14.0
[root@localhost nginx-1.14.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@localhost nginx-1.14.0]# ./configure

./configure: error: C compiler cc is not found

img_c9eeb4cdf41cde9efa3819a7074f1867.png

错误1:未找到C编辑器,报错信息如下:
解决办法:

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


然后回去继续安装配置

[root@localhost nginx-1.14.0]# ./configure

./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.

img_d426ac7c5e9104d33079fac198e30c82.png

错误2:需要pcre模块,报错信息如上图:
解决办法:

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


然后回去继续安装配置

[root@localhost nginx-1.14.0]# ./configure

又出现一个错误:

./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.

img_b7cf4be8569d3a812ad4773d18cf36eb.png

错误3:需要zlib库,报错信息如上图:
上面这个错误是说需要zlib库
解决办法:

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



然后回去继续安装配置

[root@localhost nginx-1.14.0]# ./configure

这次没有错误:

img_d1b1718976242e942c9afaa813d348fd.png
图片.png
[root@localhost nginx-1.14.0]# make
[root@localhost nginx-1.14.0]# make install

上面两步没有错误就安装成功了!

web访问Nginx,看到下图就安装成功了。

img_865254ab1dd2f03a8f46032e0e938e7f.png

开始安装完成后,在centos上面测试下是没问题的,web访问也没问题,但是在windows浏览器访问却出错访问不了,后来想想查看下iptables,把iptable关掉再去访问就没有问题。

本机测试:

img_f95581d84457344adddc0d92d3a342ac.png
图片.png

关闭iptables:

[root@localhost ~]# service iptables stop
step4:把nginx添加到系统服务中,使其可以使用service nginx start/stop/restart等。

以前启动/停止/查看状态某个服务的时候,我们常用的方法是
service [服务名] [动作]

[root@localhost ~]# service nginx status
nginx: 未被识别的服务
[root@localhost ~]#

可是如上,nginx未被识别,下面再解决下这个问题

[root@localhost sbin]# vim nginx

vim编辑(创建)nginx脚本,写入以下内容:

#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx

nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx

nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done"
;;
restart)
$0 stop
$0 start
;;
show)
ps -aux|grep nginx
;;
*)
echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
目录
相关文章
|
15天前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
14 0
|
3月前
|
应用服务中间件 Linux 网络安全
centos7 下离线安装gcc g++ nginx,并配置nginx进行网络流转发
centos7 下离线安装gcc g++ nginx,并配置nginx进行网络流转发
111 0
|
2月前
|
Linux 应用服务中间件 网络安全
CentOS7搭建本地离线局域网yum源(Httpd/Nginx+yum)
CentOS7搭建本地离线局域网yum源(Httpd/Nginx+yum)
324 0
|
3月前
|
Unix 应用服务中间件 Linux
1-Nginx介绍及安装(源码安装)
1-Nginx介绍及安装(源码安装)
44 4
|
2月前
|
缓存 负载均衡 应用服务中间件
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
71 1
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
|
15天前
|
网络协议 应用服务中间件 Linux
centos7 Nginx Log日志统计分析 常用命令
centos7 Nginx Log日志统计分析 常用命令
27 2
|
15天前
|
Linux Apache
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
12 0
|
2月前
|
存储 Linux 应用服务中间件
VMware安装无GUI版本的Linux(CentOS7)——安装Nginx示例demo
VMware安装无GUI版本的Linux(CentOS7)——安装Nginx示例demo
120 1
|
3月前
|
安全 应用服务中间件 Linux
百度搜索:蓝易云【CentOS7使用Nginx、Supervisor部署Go/Golang服务教程】
这些是在CentOS 7 x64上使用Nginx和Supervisor部署Go/Golang服务的基本步骤。根据您的需求和具体环境,可能还需要进行其他配置和调整。请确保在进行任何与网络连接和安全相关的操作之前,详细了解您的网络环境和安全需求,并采取适当的安全措施。
61 0
|
4月前
|
关系型数据库 MySQL Linux
Centos安装MySQL数据库(注意:源码安装)
Centos安装MySQL数据库(注意:源码安装)
141 0