nginx的安装
安装依赖
yum install gcc gcc-c++ automake autoconf libtool make gd gd-devel libxslt-devel -y
安装lua与lua依赖
lua安装步骤如下:
mkdir /www
mkdir /www/server #选择你自己的目录即可,不需要跟我一致
cd /www/server
tar -zxvf lua-5.4.3.tar.gz
cd lua-5.4.3
make linux test
make install
luajit安装步骤如下:
cd /home
tar -zxvf luajit2-2.1-20211210.tar.gz
cd luajit2-2.1-20211210
make install PREFIX=/www/server/luaJIT
lua依赖包安装:
cd /home
tar -zxvf lua-resty-core-0.1.23rc1.tar.gz
cd lua-resty-core-0.1.23rc1
make install PREFIX=/www/server/luaJIT
cd /home
tar -zxvf lua-resty-lrucache-0.11.tar.gz
cd lua-resty-lrucache-0.11
make install PREFIX=/www/server/luaJIT
配置luajit的环境变量:
vim /etc/profile
export LUAJIT_LIB=/www/server/luaJIT/lib
export LUAJIT_INC=/www/server/luaJIT/include/luajit-2.1
退出vim编辑后,刷新文件
source /etc/profile
安装nginx:
1. 解压与配置
cd /home
tar -zxvf nginx-1.20.2.tar.gz
cd nginx-1.20.2
./configure --user=www --group=www --prefix=/www/server/nginx --add-module=srclib/ngx_devel_kit --add-module=srclib/lua-nginx-module --add-module=srclib/ngx_cache_purge --add-module=srclib/nginx-sticky-module --with-openssl=srclib/openssl --with-pcre=srclib/pcre --with-zlib=srclib/zlib --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-http_dav_module --add-module=srclib/nginx-dav-ext-module --add-module=srclib/nginx-upsync-module --add-module=srclib/echo-nginx-module
2. 编译安装并配置nginx.conf
make -j2 && make install
cd /www/server/nginx
避免之后的./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory问题
配置如下:
echo "/www/server/luaJIT/lib" >> /etc/ld.so.conf
然后在刷新下配置文件
运行命令: ldconfig
vim /www/server/nginx/conf/nginx.conf
加入如下配置:
user www;
http
{
...
lua_package_path "/www/server/luaJIT/lib/lua/?.lua";
}
3. 创建用户组与启动nginx
因为在配置时我们要求使用www用户启动与操作nginx,所以需要创建这个www
1. 创建用户组与用户
groupadd www
useradd -r -g www www
2. 启动nginx
cd /www/server/nginx
sbin/nginx -c conf/nginx.conf