Nginx概述与安装

什么是Nginx

一款服务器软件,类似于Apache、Tomcat

Nginx还是一款HTTP和反向代理服务器,同时也是一个代理邮件服务器。除了实现网站发布的功能外,还可以提供负载均衡。

所谓负载均衡,就是当大量用户访问服务器的时候,为了减少服务器的压力,我们需要将用户分别引入各个服务器,分担服务器的压力

 

/缺点

优点:高并发、部署简单、内存消耗小、成本低

缺点:rewrite功能不够强大,模块没有Apache多

 

Nginx环境搭建

Mac系统中搭建Nginx(Linux与此类似)

1、下载Nginx  http://nginx.org/en/download.html

 

2、解压下载的压缩包

3、cd 进入解压后的文件夹

4、去 http://www.pcre.org  下载  PCRE

5、安装PCE

$ tar xvzf pcre-8.5

$ cd pcre-8.5

$ sudo ./configure --prefix=/usr/local

$ sudo make

$ sudo make install

6、./configure,所有配置使用默认值

输出如下

  nginx path prefix: "/usr/local/nginx"

  nginx binary file: "/usr/local/nginx/sbin/nginx"

  nginx modules path: "/usr/local/nginx/modules"

  nginx configuration prefix: "/usr/local/nginx/conf"

  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

  nginx pid file: "/usr/local/nginx/logs/nginx.pid"

  nginx error log file: "/usr/local/nginx/logs/error.log"

  nginx http access log file: "/usr/local/nginx/logs/access.log"

  nginx http client request body temporary files: "client_body_temp"

  nginx http proxy temporary files: "proxy_temp"

  nginx http fastcgi temporary files: "fastcgi_temp"

  nginx http uwsgi temporary files: "uwsgi_temp"

  nginx http scgi temporary files: "scgi_temp"

 

7、安装

sudo make

sudo make install

8、将/usr/local/nginx/sbin加入到环境变量里

vi ~/.bash_profile

NG_HOME=/usr/local/nginx

PATH=$PATH:$NG_HOME/sbin

 

export NG_HOME

export PATH

添加如上

source ~/.bash_profile  使配置文件生效

9、验证

sudo nginx  运行

在浏览器输入:  http://localhost

 

sudo nginx -s stop  停止

 

文件说明

在 NG_HOME下,

conf文件夹:配置文件;

sbin文件夹:存放了一个nginx命令;

html文件夹:网页程序;

log文件夹:日志文件

posted @ 2016-08-24 21:43  csnmd  阅读(254)  评论(0编辑  收藏  举报