LNMP架构应用实战——Nginx服务介绍与安装

本人花费半年的时间总结的《Java面试指南》已拿腾讯等大厂offer,已开源在github ,欢迎star!

本文GitHub https://github.com/OUYANGSIHAI/JavaInterview 已收录,这是我花了6个月总结的一线大厂Java面试总结,本人已拿大厂offer,欢迎star

原文链接:blog.ouyangsihai.cn >> LNMP架构应用实战——Nginx服务介绍与安装

LNMP架构应用实战——Nginx服务介绍与安装         

**    应部分小伙伴的需求,今天给各位小伙伴位介绍下关于近几年特别火的nginx服务,同时也是运维屌丝们必须要掌握的WEB服务当中的一种,功能还是比较强大的,因此还是得从相关介绍与安装布署开始**

1、Nginx服务介绍

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

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

**2、Nginx的特点**

**Web服务器 **

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

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

作为负载均衡服务器,它可以作为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、启动服务**

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、测试服务安装**

LNMP架构应用实战——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

titleWelcome to mingongge’s blog!/title

style

    body {

        width: 35em;

        margin: 0 auto;

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

    }

/style

/head

body

h1Welcome to mingongge’s blog!/h1

pthis blog is mingongge’s blog!!./p

pFor 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

pemwelcome to mingongge’s blog./em/p

/body

/html

LNMP架构应用实战——Nginx服务介绍与安装

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

LNMP架构应用实战——Nginx服务介绍与安装 **长按关注公众号——友侃有笑**
本人花费半年的时间总结的《Java面试指南》已拿腾讯等大厂offer,已开源在github ,欢迎star!

本文GitHub https://github.com/OUYANGSIHAI/JavaInterview 已收录,这是我花了6个月总结的一线大厂Java面试总结,本人已拿大厂offer,欢迎star

原文链接:blog.ouyangsihai.cn >> LNMP架构应用实战——Nginx服务介绍与安装


 上一篇
LAMP架构应用实战——构建博客网站 LAMP架构应用实战——构建博客网站
LAMP架构应用实战——构建博客网站   LAMP****实战项目 一:首先检查LAMP环境 [root@Centos~]# ps -ef|grep http root 1854  10 00:43 ? 00:00:00/appl
2021-04-05
下一篇 
LNMP架构应用实战——Nginx服务配置文件介绍 LNMP架构应用实战——Nginx服务配置文件介绍
LNMP架构应用实战——Nginx服务配置文件介绍 nginx的配置文件比较简单,但功能相当强大,可以自由灵活的进行相关配置,因此,还是了解下其配置文件的一此信息 1、Nginx服务目录结构介绍 安装完成后,在安装路径下就会有Nginx
2021-04-05