1、安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2、安装luajit
在/usr/local
目录下创建luajit文件夹
cd /usr/local
mkdir luajit
cd luajit
wget https://luajit.org/download/LuaJIT-2.0.5.tar.gz
tar –xvf luajit-2.0.5.tar.gz
cd luajit-2.0.5
make install
3、安装nginx
(1)下载组件
在/usr/local
目录下创建nginx文件夹,下载ngx_devel_kit、lua-nginx-module、nginx
cd /usr/local
mkdir nginx
cd nginx
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz
wget http://nginx.org/download/nginx-1.12.1.tar.gz
解压文件
tar -xvf v0.3.0.tar.gz
tar -xvf v0.10.9rc7.tar.gz
tar -xvf nginx-1.12.1.tar.gz
(2)编译nginx组件
一定要保证路径正确!
cd nginx-1.12.1
./configure --prefix=/usr/local/nginx --add-module=../ngx_devel_kit-0.3.0 --add-module=../lua-nginx-module-0.10.9rc7
(3)安装
make
make install
(4)启动nginx
/usr/local/nginx/sbin/nginx -s reload
当出现以下错误时
./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file:
找到libluajit-5.1.so.2
文件并复制到
系统 | 位置 |
---|---|
64位 | /usr/lib64 |
32位 | /usr/lib |
find / -name libluajit-5.1.so.2
一般文件存在于/usr/local/lib/libluajit-5.1.so.2
执行
cp /usr/local/lib/libluajit-5.1.so.2 /usr/lib64/
cp /usr/local/lib/libluajit-5.1.so.2.0.2 /usr/lib64
最后启动nginx
/usr/local/nginx/sbin/nginx -s reload
当出现以下错误时
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed
执行
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
查看是否成功启动
ps -ef | grep nginx
4、相关命令
进入到安装目录中
cd /usr/local/nginx/sbin
命令 | 语句 |
---|---|
启动 | ./nginx |
关闭 | ./nginx -s stop |
重启 | ./nginx -s reload |
5、配置
使用子文件配置
进入到安装目录中,打开配置文件夹
cd /usr/local/nginx/conf
创建conf.d
文件夹
mkdir conf.d
修改nginx.conf
,在http标签后面删除server内容,添加include
http{
include conf.d/*.conf;
}
进入conf.d
文件夹,新建配置文件,参考
server {
listen 8100;
server_name localhost;
# 监控访问ip
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
root html;
index index.html index.htm;
}
}
文章评论