centos中Nginx如何安装

发布时间:2021-11-26 13:42:18 作者:小新
来源:亿速云 阅读:166

这篇文章主要介绍了centos中Nginx如何安装,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。


1、Nginx服务介绍

  nginx是一个高性能的HTTP Server和代理软件,它具有高并发、且占用资源少,同时也是一个比较优秀的代理和负载均衡、缓存服务器,它可以运行于多种平台

官方网站:http://www.nginx.org



2、Nginx的特点

Web服务器

高性能的WEB服务器软件,与Apache相比,它支持更多的并发连接且占用服务器资源少,效率高

反向代理或负载均衡服务器

作为负载均衡服务器,它可以作为HTTP SERVER或DB等服务的代理服务器,类似Haproxy代理软件的功能,Nginx的代理功能相对简单,效率也不及Haproxy,同时它也是一个优秀的邮件代理服务软件

缓存服务器

Nginx还可以作缓存服务器,类似于专业的缓存软件功能



3、Nginx的优点

高并发:能支持1-2万甚至更多的并发连接(静态小文件)

内存消耗少

可以做HTTP反向代理——负载均衡的功能

内置对集群节点服务器的健康性查功能,不过功能相对较弱

通过cache插件可以实现缓存软件能够实现的功能



4、安装环境

[root@localhost ~]# cat /etc/redhat-release CentOS release 6.5 (Final)

[root@localhost ~]# uname -r 2.6.32-431.el6.x86_64



5、安装所需的pcre库

注:安装这个pcre库是为了让nginx支持HTTP Rewrite模块

创建一个专用的软件工具目录(实际生产环境中一定要养成好的规范习惯)

[root@localhost ~]# cd /download/tools/

下载pcre软件

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz

编译安装

tar zxf pcre-8.38.tar.gz

cd pcre-8.38

./configure

make

make install



6、安装Nginx

[root@centos6 tools]# useradd nginx -s /sbin/nologin -M

[root@centos6 tools]# wget http://nginx.org/download/nginx-1.10.1.tar.gz

[root@centos6 tools]# tar zxf nginx-1.10.1.tar.gz 

[root@centos6 tools]# cd nginx-1.10.1

[root@centos6 nginx-1.10.1]# ./configure \

--user=nginx \

--group=nginx \

--prefix=/application/nginx-1.10.1 \

--with-http_stub_status_module \

--with-http_ssl_module

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

[root@centos6 nginx-1.10.1]# ./configure

--user=nginx \

--group=nginx \

--prefix=/application/nginx-1.10.1 \

--with-http_stub_status_module \

--with-http_ssl_module \

--with-pcre=/download/tools/pcre-8.38

注意这里不是安装后的目录,而是源码目录

[root@centos6 nginx-1.10.1]# make && make install




7、启动服务

建立软件链接

[root@centos6 tools]# ln /application/nginx-1.10.1 /application/nginx

ln: `/application/nginx-1.10.1': hard link not allowed for directory

看到了吧,这个提示是硬链接是不允许的

[root@centos6 tools]# ln -s /application/nginx-1.10.1 /application/nginx 

[root@centos6 tools]# ll /application/nginx

lrwxrwxrwx. 1 root root 25 Nov 28 18:31 /application/nginx -> /application/nginx-1.10.1

配置规范启动

[root@centos6 tools]# cd /application/nginx/conf/

[root@centos6 conf]# cp ../sbin/nginx /etc/init.d/

[root@centos6 conf]# /etc/init.d/nginx

[root@centos6 conf]# ps -ef|grep nginx

root 151771  0 18:33 ?00:00:00 nginx: master process /etc/init.d/nginx

nginx 15178  15177  0 18:33 ?00:00:00 nginx: worker process

root 15180   2340  0 18:33 pts/0 00:00:00 grep nginx

[root@centos6 conf]# lsof -i :80

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx   15177  root    6u  IPv4  26905      0t0  TCP *:http (LISTEN)

nginx   15178 nginx    6u  IPv4  26905      0t0  TCP *:http (LISTEN)

检查语法

[root@centos6 conf]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.10.1/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.10.1/conf/nginx.conf test is successful


有的时候也会提示有错误

[root@localhost nginx-1.10.1]# /application/nginx/sbin/nginx -t /application/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

出现错误提示 提示说明无法打开libpcre.so.1这个文件,没有这个文件或目录,出现这个提示的原因是因为在系统的/etc/ld.so.conf这个文件里没有libpcre.so.1的路径配置

解决方法如下:

[root@localhost nginx-1.10.1]# find / -name libpcre.so.1

/download/tools/pcre-8.38/.libs/libpcre.so.1

/usr/local/lib/libpcre.so.1

[root@localhost nginx-1.10.1]# vi /etc/ld.so.conf

include ld.so.conf.d/*.conf

/usr/local/lib

             #添加此路径即可

[root@localhost nginx-1.10.1]# ldconfig

              #生效配置

重新检查语法

[root@localhost nginx-1.10.1]# /application/nginx/sbin/nginx -t nginx: the configuration file /application/nginx-1.10.1/conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-1.10.1/conf/nginx.conf test is successful



8、测试服务安装

centos中Nginx如何安装
看到这个界面表明安装是成功的


如果出现无法访问的现象可以从以下几个方面排错

1、防火墙是否关闭

2、与WEB服务器的联通性

3、selinux是否为disable

4、telnet下80端口

5、查看错误日志记录进行分析问题所在



9、组建个简单页面测试

nginx的站点目录如下

[root@centos6 conf]# cd /application/nginx/html/

[root@centos6 html]# ll

total 8

-rw-r--r--. 1 root root 537 Nov 28 18:29 50x.html

-rw-r--r--. 1 root root 612 Nov 28 18:29 index.html

[root@centos6 html]# cp index.html index.html.bak

[root@centos6 html]# vi index.html

<!DOCTYPE html>

<html>

<head>

<title>Welcome to mingongge's blog!</title>

<style>

    body {

        width: 35em;

        margin: 0 auto;

        font-family: Tahoma, Verdana, Arial, sans-serif;

    }

</style>

</head>

<body>

<h2>Welcome to mingongge's blog!</h2>

<p>this blog is mingongge's blog!!.</p>

<p>For online documentation and support please refer to

<a href="http://www.mingongge.com/">www.mingongge.com</a>.<br/>

Commercial support is available at

<a href="http://www.mingongge.com/">www.mingongge.com</a>.</p>

<p><em>welcome to mingongge's blog.</em></p>

</body>

</html>

centos中Nginx如何安装

至此Nginx服务安装与配置整个过程结束

感谢你能够认真阅读完这篇文章,希望小编分享的“centos中Nginx如何安装”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

推荐阅读:
  1. 如何在centos7中安装nginx
  2. centos安装nginx教程

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

centos nginx

上一篇:SBC8600 OPKG如何安装软件

下一篇:C#如何实现基于Socket套接字的网络通信封装

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》