openresty如何完美替換nginx
- 2020 年 4 月 3 日
- 筆記
下載openresty
wget https://openresty.org/download/openresty-1.15.8.1.tar.gz tar zxvf openresty-1.15.8.1.tar.gz cd openresty-1.15.8.1
安裝openresty
查看當前nginx的編譯配置
nginx -V
如下所示,"configure arguments"就是編譯nginx時的配置
nginx version: nginx/1.14.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --with-http_ssl_module
編譯openresty,把剛才的配置加到"configure"命令後方,如果需要使用lua也可以加上"–with-luajit"
./configure --with-http_ssl_module --with-luajit gmake && gmake install
gmake即GNU make,使用它的原因是非GNU平台可能佔用了make命令,在linux系統下不用考慮這個問題。GNU,在Unix系統發明後,開始出現閉源收費軟件,於是有人發起了自由軟件的計劃,即GNU計劃,宣揚開源精神,編輯器Emacs和編譯器GCC就屬於GNU下的項目,但是GNU下缺少系統內核,後來機緣巧合地與Linux進行了合作,發佈了GNU/Linux。
更換配置文件
把原有nginx配置文件移動到openresty目錄
mv /usr/local/nginx/conf/*.conf /usr/local/openresty/conf mv /usr/local/nginx/conf/conf.d /usr/local/openresty/conf
停止原nginx
nginx -s stop
啟動openresty
/usr/local/openresty/bin/openresty
如果提示"nginx: [warn] the "ssl" directive is deprecated, use the "listen … ssl"",原因是nginx1.15版本及以後已經不需要使用ssl on命令了,可以去掉。
軟鏈接到bin目錄
如果覺得命令使用不方便可以直接軟鏈接到bin目錄,並改名為nginx
ln -s /usr/local/openresty/bin/openresty /usr/local/bin/nginx