1.安装依赖包
yum install -y gcc gcc-c++ pcre-devel openssl-devel geoip-devel

2.下载需要的安装包
LuaJIT-2.0.4.zip
lua-nginx-module-master.zip
nginx_upstream_check_module-master.zip
nginx-1.11.3.tar.gz
ngx_cache_purge-2.3.tar.gz
ngx_devel_kit-master.zip

3.编译安装LuaJIT-2.0.4.zip(lua-nginx-module-master依赖uaJIT)
unzip LuaJIT-2.0.4.zip
cd LuaJIT-2.0.4
make && make install
ln -s /usr/local/lib/libluajit-5.1.so.2 /usr/lib64/libluajit-5.1.so.2
解压其他第三方模块压缩包
tar -zxvf nginx-1.11.3.tar.gz 
tar -zxvf ngx_cache_purge-2.3.tar.gz 
unzip nginx_upstream_check_module-master.zip 
unzip ngx_devel_kit-master.zip 
unzip lua-nginx-module-master.zip

cd nginx-1.11.3

隐藏版本信息
方法1(需要安装成功后修改配置文件缺点是仍然显示nginx):
vim /etc/nginx/nginx.conf
加入:
server_tokens off;
http {
    include       mime.types;
    server_tokens off;

fastcgi.conf
sed -i 's#fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;#fastcgi_param  SERVER_SOFTWARE    yaya;#g' /etc/nginx/fastcgi.conf
找到:
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
改为:
fastcgi_param SERVER_SOFTWARE yaya;

方法2推荐(修改源码头文件信息编译):
vim src/core/nginx.h
#define NGINX_VER          "yaya"
#define NGINX_VAR          "yaya"

测试环境编译参数(增加--with-debug):

./configure --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --with-debug --pid-path=/var/run/nginx/nginx.pid --with-pcre --with-http_gzip_static_module --with-http_ssl_module --with-http_realip_module --with-http_geoip_module --add-module=../nginx_upstream_check_module-master
--add-module=../ngx_cache_purge-2.3 --add-module=../ngx_devel_kit-master/ --add-module=../lua-nginx-module-master/ --with-http_stub_status_module

生产环境编译参数:
./configure --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx/nginx.pid --with-pcre --with-http_gzip_static_module --with-http_ssl_module --with-http_realip_module --with-http_geoip_module --add-module=../nginx_upstream_check_module-master
--add-module=../ngx_cache_purge-2.3 --add-module=../ngx_devel_kit-master/ --add-module=../lua-nginx-module-master/ --with-http_stub_status_module

make && make install

4.服务脚本添加/etc/init.d/nginx、隐藏版本信息
/etc/init.d/nginx

#! /bin/bash
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#  proxy and IMAP/POP3 proxy server
#
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile:/var/run/nginx/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/nginx.lock  
start() {
  [ -x $nginx ] || exit 5
  [ -f $NGINX_CONF_FILE ] || exit 6
  echo -n $"Starting $prog: "
  daemon $nginx -c $NGINX_CONF_FILE
  retval=$?
  echo
  [ $retval -eq 0 ] && touch $lockfile
  return $retval
}
stop() {
  echo -n $"Stopping $prog: "
  killproc $prog -QUIT
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f $lockfile
  return $retval
}
restart() {
  configtest || return $?
  stop
  sleep 1
  start
}
reload() {
  configtest || return $?
  echo -n $"Reloading $prog: "
  killproc $nginx -HUP
  RETVAL=$?
  echo
}
force_reload() {
  restart
}
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
  status $prog
}
rh_status_q() {
  rh_status >/dev/null 2>&1
}
case "$1" in
  start)
    rh_status_q && exit 0
    $1
    ;;
  stop)
    rh_status_q || exit 0
    $1
    ;;
  restart|configtest)
    $1
    ;;
  reload)
    rh_status_q || exit 7
    $1
    ;;
  force-reload)
    force_reload
    ;;
  status)
    rh_status
    ;;
  condrestart|try-restart)
    rh_status_q || exit 0
      ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
    exit 2
esac

chmod +x /etc/init.d/nginx
groupadd -r nginx
useradd -r -g nginx nginx

5.开启debug测试功能(前提是需要加入--with-debug编译选项)
vim /etc/nginx/nginx.conf

测试环境打开debug:
error_log  /data/logs/error.log  debug;
生产环境:
error_log  /data/logs/error.log  info;
access_log  /data/logs/access.log;

6.启动服务
/usr/sbin/nginx -c /etc/nginx/nginx.conf

/usr/sbin/nginx -V 
显示详细编译信息
configure arguments: --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx/nginx.pid --with-pcre --with-http_gzip_static_module --with-http_ssl_module --with-http_realip_module --with-http_geoip_module --add-module=../nginx_upstream_check_module-master
--add-module=../ngx_cache_purge-2.3 --add-module=../ngx_devel_kit-master/ --add-module=../lua-nginx-module-master/ --with-http_stub_status_module

重新编译需要删除的文件:
rm -rf /usr/local/nginx/
rm -rf /etc/nginx/
rm -rf /var/run/nginx/

关于debug日志的说明:
一般来讲,Nginx 的错误日志级别是 error,作为 Nginx 用户来讲,你设置成 info 就足够用了。
        但有时有些难以挖掘的 bug,需要看到更详细的 debug 级别的日志,这时候,单单把 error_log 级别设置成 debug 是不行的,Nginx 记录下来的还是 info 级别以上的信息。你需要激活 Nginx 的 debug 日志才可以得到 debug 级别的日志信息。本文简要介绍了 Nginx debug 日志的激活和配置使用。官方正文如下:
        要激活 debug 日志,Nginx 在构建时需要配置为支持 debug:
./configure --with-debug ...
        然后可以通过 error_log 指令设置 debug 级别:
error_log /path/to/log debug;
        Windows 下的 Nginx 的二进制版本一般都支持 debug 日志,因此只需设置 debug 级别即可。
        注意如果你重新指定日志时没有配置 debug 级别的话,将会禁用 debug 日志。在下面的例子中,在 server 层面上重新指定的日志将会禁用这台服务器的 debug 日志:
error_log /path/to/log debug;

http {
    server {
        error_log /path/to/log;
        ...
        为了避免这种现象的发生,要么你就注释掉重新定义的那行日志,要么你就在那行也加上 debug 级别:
error_log /path/to/log debug;

http {
    server {
        error_log /path/to/log debug;
        ...
        也可以只为特定的客户端地址发来的请求开启 debug 日志:
error_log /path/to/log;

events {
    debug_connection 192.168.1.1;
    debug_connection 192.168.10.0/24;
}

附带一份nginx的参数:

user  nginx;
worker_processes 2;
worker_rlimit_nofile 100000; #error_log logs/error.log;
#error_log logs/error.log notice;
error_log /data/logs/error.log info; #pid logs/nginx.pid; pid /var/run/nginx/nginx.pid; events {
worker_connections 2024;
multi_accept on;
use epoll;
} http { server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; access_log /data/logs/access.log; #keepalive_timeout 0;
keepalive_timeout 10;
client_header_timeout 10;
client_body_timeout 10; reset_timedout_connection on;
send_timeout 10;
limit_conn_zone $binary_remote_addr zone=addr:5m;
limit_conn addr 100;
charset UTF-8;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_min_length 1000;
gzip_comp_level 6;
open_file_cache max=100000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on; server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 10.19.50.236; #允许监控访问nginx状态
deny all;
}
#error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

日志的记录格式:

log_format access '$http_x_forwarded_for $remote_addr - $remote_user [$time_local] "$request_time" "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$host" "$upstream_http_a" "$upstream_status" "$upstream_response_time" "$upstream_cache_status" "$http_user_agent"'; access_log /data/logs/access.log access;

测试Lua是否安装成功

可以在server部分添加如下内容:

location /hell {
default_type 'text/plain';
content_by_lua 'ngx.say("hello,lua,heihei")';
}

通过访问http://ip/hello即可测试

centos6.5生产环境编译安装nginx-1.11.3并增加第三方模块ngx_cache_purge、nginx_upstream_check、ngx_devel_kit、lua-nginx的更多相关文章

  1. CentOS 6.5 生产环境编译安装LNMP

    一.环境准备 1.操作系统安装:CentOS 6.5 64位最小化安装. 2.配置好IP.DNS.网关.主机名 3.配置防火墙,开启80.3306端口 vim /etc/sysconfig/iptab ...

  2. Centos6.5 源码编译安装 Mysql5.7.11及配置

    安装环境 Linux(CentOS6.5 版).boost_1_59_0.tar.gz.mysql-5.7.11.tar.gzMySQL 5.7主要特性:    更好的性能:对于多核CPU.固态硬盘. ...

  3. Centos6.5生产环境最小化优化配置

    Centos6.5生产环境最小化优化配置,满足业务需求! 01.启动网卡 #centos6.x最小化安装后,网卡默认不是启动状态 ifup eth0  //  ifconfig eth0 up /et ...

  4. Centos7之LNMP环境编译安装

    Centos7之LNMP环境编译安装 一.系统环境准备 注:安装时间过长,只做参考!!!1.系统信息 [root@localhost ~]# uname -r 3.10.0-957.el7.x86_6 ...

  5. Centos6下Python3的编译安装

    本文转载自 Centos6下Python3的编译安装 系统环境:CentOS 6.8-Minimal 安装Python依赖包: 1 [root@Python src]# yum install zli ...

  6. centos7.6编译安装php7.2.11及redis/memcached/rabbitmq/openssl/curl等常见扩展

    centos7.6编译安装php7..11及redis/memcached/rabbitmq/openssl/curl等常见扩展 获取Php的编译参数方法: [root@eus-api-cms-bac ...

  7. nginx增加第三方模块

    增加第三方模块 ============================================================ 一.概述nginx文件非常小但是性能非常的高效,这方面完胜ap ...

  8. Debian 为nginx增加第三方模块

    为nginx增加第三方模块需要重新编译nginx的,但是debian在安装nginx的时候做了很多事情,比如systemd,/etc/nginx/里的各种文件,所以我们最好在debian源代码包的基础 ...

  9. centos6.8服务器配置之编译安装PHP、配置nginx

    php version 5.6.31.nginx version: nginx/1.10.2 1.下载: wget http://cn2.php.net/distributions/php-5.6.3 ...

随机推荐

  1. Holiday、Vacation、Days off、Leave、Break

    http://write.scu.edu.tw/view.php?bd=mistake&no=25 這些字在英文的用法中都有放假.休息的意思,但用法卻不太一樣,接下來就來看看它們的不同吧. 『 ...

  2. 【模板】倍增+Floyd

    题目大意:给定一个 N 个顶点的邻接矩阵.起点顶点.终点顶点,求至少经过 K 条边(边可以重复)从起点到终点的最短路长度,若不能到达,输出 -1. 题解:至少经过 K 条边和恰好经过 K 条边的初始条 ...

  3. Array 新增加的一些API用法

    es6中新增加了数组的一些用法,基本上是看例子就可以大致明白具体意思. Array.from Array.from方法用于将两类对象转为真正的数组:类似数组的对象和可遍历的对象(包括 ES6 新增的数 ...

  4. 洛谷 P1083 借教室

    传送门:Probem 1083 https://www.cnblogs.com/violet-acmer/p/9721160.html 一.暴力简述 首先我们不难看出,这道题--并不是一道多难的题,因 ...

  5. 算法入门及其C++实现

    https://github.com/yuwei67/Play-with-Algorithms (nlogn)为最优排序算法 选择排序 整个数组中,先选出最小元素的位置,将该位置与当前的第一位交换:然 ...

  6. (转)Go中的string和[]byte对比

    本文转自:https://sheepbao.github.io/post/golang_byte_slice_and_string/ 作者:boya 声明:本文目的仅仅作为个人mark,所以在翻译的过 ...

  7. 在eclipse中启动项目报java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space

    在我们启动项目的时候经常会出现内存溢出这个错误  设置一下内存就ok 错误信息 java.util.concurrent.ExecutionException: java.lang.OutOfMemo ...

  8. WebApi中的参数传递

    在WebApi开发过程中,遇到一些客户端参数格式传输错误,经常被问到参数如何传递的一些问题,因此就用这篇博客做一下总结,肯定其它地方呢也有类似的一些文章,但是我还是喜欢通过这种方式将自己的理解记录下来 ...

  9. CodeForces - 615D Multipliers(数论)

    http://codeforces.com/problemset/problem/615/D 题意 给出m个质因子,组成一个数n.问n的约数的乘积是多少,输出mod 1e+7的结果. 分析 从输入我们 ...

  10. UVa 11134 Fabled Rooks(贪心)

    题目链接  题意  在n*n的棋盘上的n个指定区间上各放1个'车’ , 使他们相互不攻击(不在同行或同列),输出一种可能的方法. 分析 每行每列都必须放车,把行列分开看,若行和列同时有解,则问题有解. ...