一.定义
nginx 一个高性能的http服务器 反向代理服务器 世界访问量第二
tengine 是由淘宝网发起的web服务器项目 nginx的基础上进一步开发 The Tengine Web Server
二.Nginx安装
1.执行命令添加源:
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.安装Nginx
yum install -y nginx
systemctl start nginx.service
systemctl enable nginx.service
systemctl status nginx.service
3.nginx配置文件
配置文件目录 /etc/nginx
nginx主配置文件 /etc/nginx/nginx.conf
nginx网站根目录 /usr/share/nginx
user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;events {worker_connections 1024;}http {log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log /var/log/nginx/access.log main;sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 65;types_hash_max_size 2048;include /etc/nginx/mime.types;default_type application/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;server {listen 80 default_server;listen [::]:80 default_server;server_name _;root /usr/share/nginx/html;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;location / {}error_page 404 /404.html;location = /40x.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}
三.通过ngnix构建静态网站
/usr/share/nginx/html 创建页面 hello world
echo "hello word" >> 1
四.通过ngnix构建动态网站
lnmp
五.apache 和ngnix区别
1.nginx 优势
开源
nginx 配置系统相对简单
nginx pdf zip html mp4 mpeg jpg gif png 静态文件处理 性能较好
nginx 处理任何web应用程序流量,大多数的应用程序提供了配置指南
与apache相比 并发连接,响应事件 资源使用方面更强
nginx能使网站更快
2.apache 优势
开源
灵活 存在动态模块
更加兼容unix操作系统 ms windows
更庞大的社区
与任何编程语言兼容 对静态文件有最佳的交付能力
3.图表所示
特征 | NGINX | APACHE |
---|---|---|
简单 | NGINX 的开发和创新很复杂,因为它具有复杂的架构来同时处理多个连接。 | Apache 很容易开发,因为它的每个进程一个连接的模型。 |
操作系统支持 | NGINX 在类 Unix 系统上运行,但对 Windows 的支持有限。 | Apache 兼容所有类 Unix 系统,如 Linux、BSD 等,并且完全支持 Windows。 |
基本架构 | Nginx 遵循事件驱动/单线程方法来处理客户端请求 Nginx 在一个线程中处理多个请求 | Apache 遵循进程驱动/多线程方法来处理客户端请求。 |
静态内容 | NGINX 可以同时运行数千个静态内容连接,速度比 Apache 快 2.5 倍。 | 在 Apache 中,为每个请求创建一个新线程 Apache 显示静态内容的速度较慢。 |
动态内容 | NGINX 不处理动态内容。 | Apache 在 Web 服务器本身内处理动态内容。 |
交通处理 | NGINX 可以在流量大的情况下同时有效地处理多个客户端请求。 | Apache 无法同时处理多个客户端请求以及繁重的 Web 流量。 |
内存消耗 | Nginx 使用有限的硬件资源来处理客户端请求并且消耗更少的内存 | Apache的内存消耗更多。 |
用法 | NGINX 被开发为既是 Web 服务器又是反向代理服务器。 | Apache 被开发为 Web 服务器。 |
集中配置 | NGINX 有一个相对简单的配置系统。 Nginx 不允许额外的配置。 | Apache 中的配置系统并不是那么简单。 Apache 允许通过 .htaccess 文件在每个目录的基础上进行额外配置。 |
请求口译 | Nginx 通过 URI(统一资源标识符)来解释客户端请求。 | Apache 传递文件系统位置来解释客户端请求。 |
安全 | Nginx 以更小的代码库提供更好的安全性。 | Apache 还提供了良好的安全性,但与 Nginx 相比,它的安全性较低。此外,Apache 的代码库非常高。 |
功能模块 | NGINX 的核心版本不支持动态模块,但 NGINX plus 是 NGINX 的付费版本,支持动态模块。 模块的加载和卸载很复杂。 | Apache 由可以关闭/打开的动态加载模块组成。 apache中模块的加载和卸载更简单 |
支持 | NGINX 由成立于 2011 年的 NGINX, Inc 公司处理。社区支持通过 IRC(Internet 中继聊天)、邮件列表和堆栈溢出来完成。 | Apache 服务器由来自世界各地的用户社区处理,并由 Apache 软件基金会协调。社区支持通过 IRC、邮件列表、堆栈溢出和论坛完成。 |