openresty nginx php,diy 你的nginx-OpenResty

OpenResty

OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

安装

openresty依赖库为:perl 5.6.1+, libreadline, libpcre, libssl

centos:yum install readline-devel pcre-devel openssl-devel

ubuntu:apt-get install libreadline-dev libpcre3-dev libssl-dev perl

编译安装:curl -O https://openresty.org/download/openresty-1.17.8.2.tar.gz

tar -zvxf openresty-1.17.8.2.tar.gz

cd openresty-1.17.8.2

make

make install

将默认安装到/usr/local/openresty 目录中

使用

创建一个新目录 openrestyTest,以及创建logs和conf目录:[tioncico@tioncico-server homeTest]$ mkdir openrestyTest

[tioncico@tioncico-server homeTest]$ cd openrestyTest/

[tioncico@tioncico-server openrestyTest]$ mkdir ./logs ./conf

[tioncico@tioncico-server openrestyTest]$

logs将存放openresty的日志,conf存放配置文件

在conf中新建一个nginx.conf文件:worker_processes  1;

error_log logs/error.log;

events {

worker_connections 1024;

}

http {

server {

listen 9000;

location / {

default_type text/html;

content_by_lua '

ngx.say("

Hello, World!

")

';

}

}

}

可以看到,配置跟nginx的一致,不过在location块中多了个content_by_lua块,通过这个可以执行lua脚本

启动openresty:/usr/local/openresty/nginx/sbin/nginx -p ./ -c ./conf/nginx.conf

-p后面为我们的项目目录,也就是 openrestyTest目录中,-c为配置文件路径

访问 ip:9000即可看到输出:

b6c9324a94a08ee7a625ce455c7fa14e.png

停止openresty/usr/local/openresty/nginx/sbin/nginx -p ./ -s stop

重启 openresty/usr/local/openresty/nginx/sbin/nginx -p ./ -s reload

注意,启动和停止都必须指定-p,否则守护进程找不到pid文件

通过openresty配置项目

nginx.conf写法:worker_processes  1;

error_log logs/error.log;

events {

worker_connections 1024;

}

http {

server {

listen 9000;

server_name xxx.easyswoole.cn;

index index.php index.html index.htm default.php default.htm default.html;

root /www/wwwroot/homeTest/openrestyTest;

################################### 宝塔 php-fpm支持  #################################

location ~ [^/]\.php(/|$)

{

try_files $uri =404;

fastcgi_pass  unix:/tmp/php-cgi-72.sock;

fastcgi_index index.php;

set $real_script_name $fastcgi_script_name;

if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {

set $real_script_name $1;

set $path_info $2;

}

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REQUEST_SCHEME     $scheme;

fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param  REDIRECT_STATUS    200;

fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;

fastcgi_param SCRIPT_NAME $real_script_name;

fastcgi_param PATH_INFO $path_info;

}

################ 上面都是宝塔fpm支持的写法 ###################################

## 这个是额外的openresty定义写法

location /openrestyTest {

default_type text/html;

content_by_lua '

ngx.say("

Hello, World!

")

';

}

}

}

在openrestyTest目录新增index.php:<?php

echo "666";

重启之后,继续访问:[tioncico@tioncico-server openrestyTest]$ curl http://xxx.easyswoole.cn:9000/openrestyTest

Hello, World!

[tioncico@tioncico-server openrestyTest]$ curl http://xxx.easyswoole.cn:9000/

666[tioncico@tioncico-server openrestyTest]$

本文为仙士可原创文章,转载无需和我联系,但请注明来自仙士可博客www.php20.cn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值