照着文檔(http://openresty.org/cn/getting-started.html)的提示寫個openresty的helloworld,運行 nginx -p `pwd`/ -c conf/nginx.conf 時出現:…unknown directive "content_by_lua_block" ,有的博客說是安裝的openresty的版本過低,但我尋思着我的是最新版,應該不是這個原因,后來看到這篇討論:https://segmentfault.com/q/1010000019781462/,感覺有點方向了,又在github上看到:https://github.com/openresty/lua-nginx-module/issues/1554一段這樣的話:
Seems like you're not invoking openresty's nignx.
You may have multiple nginx executables in your system.
Try invoking openresty's nginx binary explicitly via its full path instead of relying on changing PATH environment variable values.
猜測原因是自己使用的nginx不是openresty中的自帶的nginx。
后來猛地想起,自己在執行 ./configure的時候貌似忽略了一些參數。。。
官方給出的參考參數如下:(忘了自己當時少添加了哪個(或者是根本沒有加參數))
./configure --prefix=/opt/openresty \ --with-luajit \ --without-http_redis2_module \ --with-http_iconv_module \ --with-http_postgres_module
於是重新執行編譯一次openresty,這次將上面的后四個參數全加上去,再按照之前的步驟來,執行成功!
稍作記錄,如果你遇到相同的問題,希望可以幫到你!