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:是一個指令,能夠經過下面的連接查看: