Nginx之LNMP、LNNMP、LNNNMP架构实现及缓存技术

1. 前言

1.1 Nginx简介

Nginx是一款由俄罗斯程序员Igor Sysoev所开发轻量级的网页服务器、反向代理服务器以及电子邮件(IMAP/POP3)代理服务器。可以在目前所有主流的操作系统上运行。

Nginx采用模块化设计架构,易扩展;使用多线程处理客户请求,减少了进程上下文切换的开销;使用epoll或者kqueue事件驱动模型,提高了并发处理性能。

1.2 Tengine介绍

Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。

Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。

特性

今天的实验将使用Tengine替代Nginx来搭建LNMP、LNNMP和LNNNMP。这三种架构后端都使用同样的PHP-FPM、MariaDB,这些服务器搭建参看以前的博文。

PHP-FPM,使用FastCGI协议和Nginx的WEB服务器通信。

MariadB,提供数据库服务器。

2. 环境准备

2.1 PHP-FPM

提供测试页面index.php

# mkdir /web/nginx # vim /web/nginx/index.php<html> <head><title>dynamic</title></head><body><table class="tb_show"> <tr> <td>Client IP is</td> <td class="content_show"><?php echo getenv(‘REMOTE_ADDR’) . ‘:’ . getenv(‘REMOTE_PORT’) ?></td> </tr> <tr> <td>Server IP is </td> <td class="content_show"><?php echo getenv(‘SERVER_ADDR’) . ‘:’ . getenv(‘SERVER_PORT’) ?></td> </tr> <tr> <td colspan="2"><?phpmysql_connect ( "192.168.23.121" , "wp" , "wp" ) or die( "Could not connect: " . mysql_error ());printf ( "MySQL server version: %s\n" , mysql_get_server_info ());?> </td> </tr></table></body></html>

2.2 Tengine安装

# yum -y install gcc openssl-devel pcre-devel # groupadd -r nginx# useradd -r -g nginx -s /bin/nologin nginx

编译安装前修改版本信息,让客户端无法看到真实的服务器信息和版本号。

# tar xf tengine-2.0.3.tar.gz # cd tengine-2.0.3# sed -i \ -e ‘s/\(#define[[:space:]]\+TENGINE_VER[[:space:]]\+\).*/\1"MeXP\/1.0.1"/’ \ -e ‘s/\(#define[[:space:]]\+NGINX_VER[[:space:]]\+\).*/\1"MeXP\/1.0.0"/’ \ ./src/core/nginx.h# ./configure –prefix=/usr/local/nginx \ –error-log-path=/var/log/nginx/error.log \ –http-log-path=/var/log/nginx/access.log \ –pid-path=/var/run/nginx/nginx.pid \ –lock-path=/var/lock/nginx.lock \ –user=nginx –group=nginx \ –with-http_ssl_module \ –with-http_flv_module \ –with-http_stub_status_module \ –with-http_gzip_static_module \ –http-client-body-temp-path=/usr/local/nginx/client \ –http-proxy-temp-path=/usr/local/nginx/proxy \ –http-fastcgi-temp-path=/usr/local/nginx/fcgi \ –http-uwsgi-temp-path=/usr/local/nginx/uwsgi \ –http-scgi-temp-path=/usr/local/nginx/scgi \ –with-pcre# make && make install# /usr/local/nginx/sbin/nginx -v Tengine version: MeXP/1.0.1 (MeXP/1.0.0)

导出环境变量

# vim /etc/profile.d/nginx.shexport PATH=/usr/local/nginx/sbin:$PATH # source /etc/profile.d/nginx.sh

3. LNMP

3.1 规划

Nginx是WEB服务器。

3.2 提供一个测试用index.html

# vim /usr/local/nginx/html/index.htmldynamicThis is a static page of WEB1

3.3 nginx配置文件

user nginx; worker_processes auto;#pid/var/run/nginx.pid; error_log /var/log/nginx/error.log;events { use epoll; worker_connections 1024;}http { includemime.types; default_type application/octet-stream; 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; sendfileon; #tcp_nopushon; #keepalive_timeout 0; keepalive_timeout 5; #gzip on; server { listen80;server_name WEB1;add_header X-upS WEB1-$server_addr:$server_port;#charset koi8-r;#access_log logs/host.access.log main;location / { root html;index index.html index.htm;}#error_page 404/404.html;# redirect server error pages to the static page /50x.html #error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 #location ~ \.php$ {# roothtml;fastcgi_pass 192.168.23.85:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /web/nginx$fastcgi_script_name;fastcgi_param QUERY_STRING$query_string;includefastcgi_params;}# deny access to .htaccess files, if Apache’s document root # concurs with nginx’s one##location ~ /\.ht {# deny all;#} }}

3.4 SysV风格脚本

还要高声歌唱。那歌声,一定是响遏流云的,

Nginx之LNMP、LNNMP、LNNNMP架构实现及缓存技术

相关文章:

你感兴趣的文章:

标签云: