在Ubuntu 14.04 64bit上安装OpenResty 1.9.7.4

时间:2022-10-06 04:34:45

为了自己的ThinkPad T420上面的Ubuntu可以使用openresty开发,我特地记录一下安装过程:

安装依赖包

apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make build-essential
下载源码并编译安装
wget https://openresty.org/download/openresty-1.9.7.4.tar.gz
tar zxvf openresty-1.9.7.4.tar.gz -C ~/program_develop/
cd ~/program_develop/
cd openresty-1.9.7.4

./configure --prefix=/opt/openresty --with-luajit --without-http_redis2_module --with-http_iconv_module
make
sudo make install
设置环境变量
vim /etc/profile
或者
vim ~/.bashrc
export PATH=/opt/openresty/nginx/sbin:$PATH
source /etc/profile

source ~/.bashrc

echo $PATH

查看环境变量是否设置正确?

配置文件
cd ~/program
mkdir -p openresty-test openresty-test/conf openresty-test/logs
在conf目录下面手动创建
vim nginx.conf
启动nginx
nginx -p ~/program/openresty-test/

客户端测试

curl http://localhost:6699 -i
中途如果更改了nginx.conf,使用下面的命令来测试语法正确性

sudo nginx -p ~/program/openresty-test -t

停止

sudo nginx -p ~/program/openresty-test -s reload


需要注意的问题
与默认安装的nginx不共存,会相互干扰,因为端口不一样。如果安装openresty之前系统中已经安装有nginx,需要彻底卸载。默认安装的nginx的配置文件在/etc/nginx/nginx.conf,可以将其服务停掉,以避免干扰
sudo service nginx stop
需要彻底删除原有nginx相关目录下面的所有文件。

我按照上面的方法彻底删除nginx后,发现sudo命令下找不到nginx,只有在nginx可执行程序的那一目录路径下面才能使用下面的命令
sudo ./nginx -p ~/program/openresty-test/ -t
sudo ./nginx -p ~/program/openresty-test/ -s reload
第一条命令是测试配置文件是否有错误,第二条命令是重新加载配置文件(如果语法没有错误)

参考文献
[1].https://moonbingbing.gitbooks.io/openresty-best-practices/content/openresty/install_on_ubuntu.html