openresty搭建高性能服务端2---helloworld

1.安装OpenResty:

下面是说明:

https://openresty.org/cn/linux-packages.html

ubuntu系统可以按照链接里面的教程安装openresty,如果是类ubuntu的系统可能会出一些问题,可以通过源码安装:

下载源码包:

wget https://openresty.org/download/openresty-1.13.6.2.tar.gz

我把文件放到/usr/local/src下,并解压

sudo tar -zxvf  openresty-1.13.6.2.tar.gz

安装需要准备相应的依,因为我的是deepin,用的源是ubuntu的,所有我看的是ubuntu的部分的说明:

apt-get install libpcre3-dev  libssl-dev perl make build-essential curl

进入安装目录

cd /usr/local/src/openresty-1.13.6.2

可以通过./configure --help查看各种模块,因为刚开始做,所以我一切都是默认

./configure

如果报错说明有些依赖没有安装,需要手动安装一下。

没有报错的话进行编译安装

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

出现:


Welcome to OpenResty!

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:是一个制定,可以通过下面的链接查看:

https://github.com/openresty/lua-nginx-module#directives

猜你喜欢

转载自www.cnblogs.com/callmelx/p/11123730.html