一个80后
程序员的笔记

[Centos]编译安装Nginx

1、安装LuaJIT

#下载地址:http://luajit.org/download.html
#         https://github.com/openresty/lua-nginx-module/tags
#         https://github.com/simplresty/ngx_devel_kit/tags
#工具包 https://gitee.com/bbhsky/Nginx-Setup.git
tar zxvf LuaJIT-2.0.5.tar.gz
cd LuaJIT-2.0.5/
make
make install PREFIX=/usr/local/luajit-2.0.5
ln -sf /usr/local/luajit-2.0.5/ /usr/local/luajit
cat > /etc/ld.so.conf.d/luajit.conf<<EOF
/usr/local/luajit/lib
EOF
ln -sf /usr/local/luajit/lib/libluajit-5.1.so.2 /usr/lib64/libluajit-5.1.so.2
ln -sf /usr/local/luajit/lib/libluajit-5.1.so.2 /usr/lib/libluajit-5.1.so.2
cat >/etc/profile.d/luajit.sh<<EOF
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
EOF

2、下载扩展模块:

2.1、合并CSS、JS  nginx-http-concat

#下载地址:git://github.com/alibaba/nginx-http-concat.git
#工具包 https://gitee.com/bbhsky/Nginx-Setup.git
git clone git://github.com/alibaba/nginx-http-concat.git
mv nginx-http-concat /usr/local/nginx_module/nginx-http-concat

===============conf文件使用方法==========================
location /static/css/ {
    concat on;
    concat_max_files 20;
}
location /static/js/ {
    concat on;
    concat_max_files 30;
}
location /static/ {
    concat on;
    concat_max_files 20;
    concat_unique off;
}
页面使用方法:
<link rel="stylesheet" href="??foo1.css,foo2.css,subdir/foo3.css?v=2345" />
<script src="??bar1.js,bar22.css,subdir/bar3.js?v=3245" />
========================配置参数======================
参数:concat on | off
说明:是否开启功能
默认:default: concat off
环境:context: http, server, location

参数:concat_types MIME types
说明:功能类型文件
默认:default: concat_types: text/css application/x-javascript
环境:context: http, server, location

参数:concat_unique on | off
说明:是否只允许同类型文件
默认:default: concat_unique on
环境:context: http, server, location

参数:concat_max_files number p
说明:最大允许文件个数
默认:default: concat_max_files 10
环境:context: http, server, location

参数:concat_delimiter: string
说明:自定义分隔符,一般默认为","
默认:default: NONE
环境:context: http, server, locatione

参数:concat_ignore_file_error: on | off
说明: 是否忽略文件请求错误,例如404和403等
默认:default: off
环境:context: http, server, location

3、编译安装Nginx

#下载地址:http://nginx.org/en/download.html
#工具包 https://gitee.com/bbhsky/Nginx-Setup.git
tar zxvf nginx-1.15.3.tar.gz
cd nginx-1.15.3
groupadd www
useradd -s /sbin/nologin -g www www
./configure --user=www --group=www --prefix=/usr/local/nginx-1.15.3 --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/src/Centos7-setup/openssl-1.1.0-stable-SNAP-20180901/ --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --add-module=/root/src/Nginx-Setup/lua-nginx-module-0.10.13 --add-module=/root/src/Nginx-Setup/ngx_devel_kit-0.3.0 --add-module=/usr/local/nginx_module/nginx-http-concat/
#如果报错lua的 执行 yum install lua-devel
make && make install
ln -sf /usr/local/nginx-1.15.3/ /usr/local/nginx
ln -sf /usr/local/nginx/sbin/nginx /usr/bin/nginx
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
cp conf/nginx.conf /usr/local/nginx/conf/nginx.conf
cp -ra conf/rewrite /usr/local/nginx/conf/rewrite
sed -i "/location \/nginx_status/i\        location /lua\n        {\n            default_type text/html;\n            content_by_lua 'ngx.say\(\"hello world\"\)';\n        }\n" /usr/local/nginx/conf/nginx.conf
mkdir -p /home/wwwroot
chmod +w /home/wwwroot
mkdir -p /home/wwwlogs
chmod 777 /home/wwwlogs
mkdir /usr/local/nginx/conf/vhost
mkdir /home/wwwroot/default
chown -R www:www /home/wwwroot
cat >>/usr/local/nginx/conf/fastcgi.conf<<EOF
fastcgi_param PHP_ADMIN_VALUE "open_basedir=\$document_root/:/tmp/:/proc/";
EOF
cp init.d/nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
#创建系统服务
vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/bin/nginx -t
ExecStart=/usr/bin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target


systemctl enable nginx.service
systemctl start nginx.service

遇见的错误:

 ./configure: error: ngx_http_lua_module requires the Lua library.
yum install -y lua-devel

赞(23) 打赏
未经允许不得转载:笨笨天地 » [Centos]编译安装Nginx
分享到: 更多 (0)

相关推荐

  • 暂无文章

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏