Nginx源码安装及应用

简介:

一:Nginx简介:

Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器。在高连接并发的情况下,Nginx是Apache服务器不错的替代品。 Nginx作为负载均衡服务器:Nginx 既可以在内部直接支持Rails和PHP 程序对外进行服务,也可以支持作为HTTP代理服务器对外进行服务。作为邮件代理服务器:Nginx 同时也是一个非常优秀的邮件代理服务器。

二:源码安装:

[root@lyt ~]# mkdir /mnt/cdrom

[root@lyt ~]# mount /dev/cdrom /mnt/cdrom/

[root@lyt ~]# cd /mnt/cdrom/Server/

[root@lyt Server]# vim /etc/yum.repos.d/rhel-debuginfo.repo #编辑本地yum

image

这里需要安装pcre正则函数库:

[root@lyt Server]# ll pcre*

image 

[root@lyt Server]# yum list all |grep pcre       #查看pcre的相关信息

image

[root@lyt Server]# yum install pcre-devel          #使用yum安装pcre-devel

[root@lyt Server]# cd

安装libevent:(事件触发的网络库)

[root@lyt ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/

[root@lyt ~]# cd /usr/local/src/

[root@lyt src]# cd libevent-2.0.16-stable/

[root@lyt libevent-2.0.16-stable]# ./configure

[root@lyt libevent-2.0.16-stable]# make

[root@lyt libevent-2.0.16-stable]# make install

[root@lyt libevent-2.0.16-stable]# vim /etc/ld.so.conf.d/libevent.conf     #编辑该文件如图:

image

[root@lyt libevent-2.0.16-stable]# ldconfig –v      #手动调用库文件

[root@lyt libevent-2.0.16-stable]# ldconfig -pv |grep libevent         #查看调用结果:

image

安装nginx:

[root@lyt lib]# cd

[root@lyt ~]# tar -zxvf nginx-1.0.11.tar.gz -C /usr/local/src

[root@lyt ~]# cd /usr/local/src/

[root@lyt src]# cd nginx-1.0.11/

[root@lyt nginx-1.0.11]# groupadd  -r  nginx     #创建一个系统组号nginx

[root@lyt nginx-1.0.11]# useradd -r -g nginx -s /bin/false  -M nginx         #创建一个系统账号nginx,加入系统组nginx,-M表示系统账号不需要创建家目录。使用/bin/false    ,-s表示shell。也可以使用-s  /sbin/nologin

[root@lyt nginx-1.0.11]# ./configure \

image

[root@lyt nginx-1.0.11]# make

[root@lyt nginx-1.0.11]# make install

[root@lyt nginx-1.0.11]# mkdir -pv /var/tmp/nginx/client       #创建目录。(在上个图片中没有创建记录客户端信息的目录)

[root@lyt nginx-1.0.11]# nginx       #启动nginx服务

[root@lyt nginx-1.0.11]# netstat -tupln |less       

image

image

应用1:使用虚拟目录访问站点:

[root@lyt ~]# mkdir /abc

[root@lyt ~]# echo "lasdflas">/abc/index.html      #在/abc目录下创建index.html

image

[root@lyt abc]# pkill -1 nginx       #重新加载配置文件

image

应用2:基于ip地址的虚拟主机:

[root@lyt ~]# mkdir /cba

[root@lyt ~]# echo "cba">/cba/index.html

[root@lyt ~]# vim /etc/nginx/nginx.conf

image

[root@lyt ~]# pkill -1 nginx        #重新加载

image

image

应用3:基于主机头的虚拟主机:

[root@lyt ~]# ifconfig eth0:1 down           #将eth0:1的地址停止使用

[root@lyt ~]# vim /etc/nginx/nginx.conf

编辑本地计算机的hosts文件:

image

[root@lyt ~]# pkill -1 nginx

image

image

应用4:基于端口号的虚拟主机:

[root@lyt ~]# vim /etc/nginx/nginx.conf

image

[root@lyt ~]# pkill -1 nginx

image

image










本文转自 liuyatao666 51CTO博客,原文链接:http://blog.51cto.com/5503845/979433,如需转载请自行联系原作者
目录
相关文章
|
3月前
|
Kubernetes 应用服务中间件 nginx
百度搜索:蓝易云【使用Kubernetes部署Nginx应用教程】
现在,你已经成功在Kubernetes集群上部署了Nginx应用。通过访问Service的外部IP地址,你可以访问Nginx服务。
44 4
|
4月前
|
安全 应用服务中间件 nginx
百度搜索:蓝易云【使用Debian、Docker和Nginx部署Web应用教程】
这些是在Debian上使用Docker和Nginx部署Web应用的基本步骤。根据您的需求和具体环境,可能还需要进行其他配置和调整。请确保在进行任何与网络连接和安全相关的操作之前,详细了解您的网络环境和安全需求,并采取适当的安全措施。
47 0
|
6月前
|
应用服务中间件 nginx Windows
windows下DOS命令杀掉Nginx应用进程
windows下DOS命令杀掉Nginx应用进程
|
7月前
|
网络协议 应用服务中间件 nginx
使用Dockerfile编写源码安装Nginx镜像
使用Dockerfile编写源码安装Nginx镜像
102 0
|
9月前
|
缓存 前端开发 应用服务中间件
|
4月前
|
Unix 应用服务中间件 Linux
1-Nginx介绍及安装(源码安装)
1-Nginx介绍及安装(源码安装)
54 4
|
15天前
|
运维 Serverless 应用服务中间件
Serverless 应用引擎产品使用之在阿里云Serverless中函数计算FC nginx 部署上去之后放置静态页面如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
228 0
|
3月前
|
Java 应用服务中间件 网络安全
Nginx配置静态页面+springboot应用+swagger+SSL的实现
Nginx配置静态页面+springboot应用+swagger+SSL的实现
|
4月前
|
负载均衡 应用服务中间件 nginx
Nginx四层负载均衡在秒杀系统中的应用
Nginx四层负载均衡在秒杀系统中的应用
26 0
|
4月前
|
负载均衡 应用服务中间件 nginx
Nginx负载均衡选择在秒杀系统中的应用
Nginx负载均衡选择在秒杀系统中的应用
47 0