1.安装OpenResty:html
下面是说明:linux
https://openresty.org/cn/linux-packages.htmlnginx
ubuntu系统能够按照连接里面的教程安装openresty,若是是类ubuntu的系统可能会出一些问题,能够经过源码安装:git
下载源码包:github
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
我把文件放到/usr/local/src下,并解压web
sudo tar -zxvf openresty-1.13.6.2.tar.gz
安装须要准备相应的依,由于个人是deepin,用的源是ubuntu的,全部我看的是ubuntu的部分的说明:ubuntu
apt-get install libpcre3-dev libssl-dev perl make build-essential curl
进入安装目录vim
cd /usr/local/src/openresty-1.13.6.2
能够经过./configure --help查看各类模块,由于刚开始作,因此我一切都是默认服务器
./configure
若是报错说明有些依赖没有安装,须要手动安装一下。curl
没有报错的话进行编译安装
make make install
完成之后发现,/usr/local/下多了一个openresty目录。
2.使用openresty:
由于我本地存在一个nginx,安装openresty后须要注意两个nginx.conf的端口不能重复。
修改nginx.conf配置将默认80端口改成,6001端口:
cd /usr/local/openresty/nginx/conf
vim nginx.conf
只是修改server下的端口好其余不变。
重启nginx
cd /usr/local/openresty/nginx/sbin ./nginx -c /usr/local/openresty/nginx/conf/nginx.conf ./nginx -s reload
出现:
If you see this page, the OpenResty web platform is successfully installed and working. Further configuration is required.
For online documentation and support please refer to openresty.org.
Commercial support is available at openresty.com.
Thank you for flying OpenResty.
3.helloworld的实现:
建议开发的时候将openresty目录发到vscode里面开发,修改目录所属权限
修改nginx.conf文件:
location / { root html; index index.html index.htm; } #下面是新增的 location /hello { default_type text/html; content_by_lua_block { ngx.say("<p>hello, world</p>") } }
当服务器请求的路径为/hello的时候会导引hello,world
conent_by_lua_block:是一个指令,能够经过下面的连接查看: