一、了解openresty
一个全功能的 Web 应用服务器,它打包了标准的Nginx核心,很多的常用的第三方模块,以及它们的大多数依赖项。OpenResty 通过汇聚各种设计精良的 Nginx 模块,从而将 Nginx 有效的变成一个强大的 Web 应用服务器,这样, Web 开发人员可以使用 Lua 脚本语言调动 Nginx 支持的各种C以及Lua 模块,快速构造出足以胜任 10K+ 并发连接响应的超高性能Web 应用系统.OpenResty 的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如MySQL,PostgreSQL,~Memcaches 以及 ~Redis 等都进行一致的高性能响应.
二、下载,安装准备openresty
web服务器 IP:192.168.0.167
PHP IP:192.168.0.162
MySQL服务器 IP:192.168.0.163
下载地址:http://openresty.org/download/
下载:wget ‘http://openresty.org/download/ngx_openresty-VERSION.tar.gz’
安装依赖包:perl 5.6.1+ libreadline libpcre libssl
Fedora 、redhat、centos:readline-devel pcre-devel openssl-devel
三、安装openresty
1.tar xzvf ngx_openresty-VERSION.tar.gz
2.cd ngx_openresty-VERSION/
3../configure
可以设置一下参数:./configure --prefix=/opt/openresty --with-luajit --without-http_redis2_module --with-http_iconv_module --with-http_postgres_module
4.gmake
5.gmake install
可能出现的问题:
./configure: error: ngx_postgres addon was unable to detect version of the libpq library.
ERROR: failed to run command: sh ./configure --prefix=/opt/openresty/nginx \...

安装:postgresql-devel
yum install postgresql-devel
四、配置openresty
配置文件位置:vim /opt/openresty/nginx/conf/nginx.conf
修改:server_name localhost --> server_name 192.168.0.167(本机IP地址)
启动:/opt/openresty/nginx/sbin/nginx (停止在后面加-s stop )
五、测试openresty
在浏览器输入:192.168.0.167 显示如下表示成功
参考文档:http://www.openresty.org/cn/index.html
六、PHP(yum 安装)
yum install php php-fpm
修改php所在主机的配置文件
vim /etc/php-fpm.d/www.conf
listen = 192.168.0.162:9000 监听端口
listen.allowed_clients = 192.168.0.167 接受192.168.0.167 的请求 若有多个用逗号隔开
ps:重启php-fpm
七、配置OpenResty支持PHP
编辑配置文件:vim /opt/openresty/nginx/conf/nginx.conf
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000; 把请求转给此IP地址处理。我的为192.168.0.162:9000
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 红色部分表示在php所在主机的那个位置找请求文件改为存放php文件目录的地方。我的为/var/www/html
# include fastcgi_params;
#}
去掉配置文件中此段前面的#
ps:重启nginx 线上服务器最好用 reload
八、测试php
注意防火墙:不行就关了,否则注意在用的端口是否防火墙允许通信
在php主机下编写测试文件:vim /var/www/html/index.php
内容:<?php phpinfo(); ?> 显示如下表示成功
九、wordpress应用
1.下载最新wordpress压缩包 eg:wordpress-4.0.1.zip
2.上传wordpress在openresty主机的/opt/openresty/nginx/html/文件目录下和php的主机的php文件所在的目录eg:/var/www/html
3.分别解压 unzip wordpress-4.0.1.zip
4.配置openresty支持:
location / {
root html/wordpress;
index index.html index.php
}
location ~ \.php$ {
root html;
fastcgi_pass 192.168.0.162:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress$fastcgi_script_name;
include fastcgi_params;
}
ps:重启nginx应用
十、安装mysql
1.安装:yum install mysql-server
2.启动mysql服务设置密码
启动:/etc/init.d/mysqld start
设置密码: mysqladmin -uroot password 输入密码(eg: 888admin)
3.进入mysql
方法一:mysql -uroot -p 密码(eg:888admin)
方法二:mysql -uroot -p 回车 。然后提示Enter password: 再输入密码
4.新建数据库:create database 数据库名 (eg:wordpress)
5.设置php主机(192.168.0.162)访问权限
格式:grant all on 要连接的数据库.* to 数据库使用用户名@要来连接的主机IP地址 identifed by “数据库密码”
eg :grant all on wordpress.* to localhost@192.168.0.162 identifed by “888admin”
十一、设置wordpress
1.在浏览器输入192.168.0.167/index.php
2.阅读页面内容,然后点击let's go
3.填写内容(填写自己对应的内容):
database --> wordpress
username --> localhost
password --> 888admin
database host --> 192.168.0.163
4.submit
如果成功就开始填写标题 用户名 密码 邮箱等信息
如果失败
cp wp-config-sample.php wp-config.php
vim wp-config.php
define('DB_NAME', 'database_name_here'); /** MySQL database username */ define('DB_USER', 'username_here'); /** MySQL database password */ define('DB_PASSWORD', 'password_here'); /** MySQL hostname */ define('DB_HOST', 'localhost'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');
填入安装mysql时设置的数据,我设置的如下:
/** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'localhost'); /** MySQL database password */ define('DB_PASSWORD', '888admin'); /** MySQL hostname */ define('DB_HOST', '192.168.0.163'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');
重新在浏览器输入192.168.0.167/index.php 然后install now 即可
十二、登陆成功