centos6.5生产环境编译安装nginx-1.11.3并增加第三方模块ngx_cache_purge、nginx_upstream_check、ngx_devel_kit、lua-nginx
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的更多相关文章
- CentOS 6.5 生产环境编译安装LNMP
一.环境准备 1.操作系统安装:CentOS 6.5 64位最小化安装. 2.配置好IP.DNS.网关.主机名 3.配置防火墙,开启80.3306端口 vim /etc/sysconfig/iptab ...
- Centos6.5 源码编译安装 Mysql5.7.11及配置
安装环境 Linux(CentOS6.5 版).boost_1_59_0.tar.gz.mysql-5.7.11.tar.gzMySQL 5.7主要特性: 更好的性能:对于多核CPU.固态硬盘. ...
- Centos6.5生产环境最小化优化配置
Centos6.5生产环境最小化优化配置,满足业务需求! 01.启动网卡 #centos6.x最小化安装后,网卡默认不是启动状态 ifup eth0 // ifconfig eth0 up /et ...
- Centos7之LNMP环境编译安装
Centos7之LNMP环境编译安装 一.系统环境准备 注:安装时间过长,只做参考!!!1.系统信息 [root@localhost ~]# uname -r 3.10.0-957.el7.x86_6 ...
- Centos6下Python3的编译安装
本文转载自 Centos6下Python3的编译安装 系统环境:CentOS 6.8-Minimal 安装Python依赖包: 1 [root@Python src]# yum install zli ...
- 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 ...
- nginx增加第三方模块
增加第三方模块 ============================================================ 一.概述nginx文件非常小但是性能非常的高效,这方面完胜ap ...
- Debian 为nginx增加第三方模块
为nginx增加第三方模块需要重新编译nginx的,但是debian在安装nginx的时候做了很多事情,比如systemd,/etc/nginx/里的各种文件,所以我们最好在debian源代码包的基础 ...
- 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 ...
随机推荐
- Python基础-简介一
一.Python介绍 1. Python的应用领域及流行程度 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间, ...
- 简单认识python(一)
最近本宝宝被一部小说迷的神魂颠倒的,在网络上四处找免费的小说资源,一直哭唧唧的等待着每天更新的一章.实在是太可怜了,本宝宝决定自己学python,自己抓包小说. 既然知道目的地了,那就和本宝宝一起打怪 ...
- javascript面向对象精要第四章构造函数和原型对象整理精要
- python的异常处理try/except 万能处理exception
1.try方式 try: age=int(input(">>>")) int(age)#主逻辑 num=input(">>>>& ...
- Java项目怎么使用Swagger生成API文档?
一.环境1. JAVA82. MAVEN 3.0.53. IDEA 2016.2.54. spring boot 1.4.1 <dependency> <groupId>io. ...
- 安装完office后 在组件服务里DCOM配置中找不到
这个主要是64位系统的问题,excel是32位的组件,所以在正常的系统组件服务里是看不到的 可以通过在运行里面输入 comexp.msc -32 来打开32位的组件服务,在里就能看到excel组件了
- mysql名词解释
什么是QPS? 单位时间内所处理的事务数 什么是TPS? 单位时间内所处理的查询数 响应时间 并发量 同时处理的查询请求的数量 什么是吞吐量?
- centos7下安装nginx的方法
没有用tar包的方法,太麻烦,还需要找,还需要编译,还需要下乱七八糟的依赖模块.麻烦的一逼,看网上说的.就采用了在线安装的方法.很快.注意一下,这种方法安装是安装到系统默认的位置.我也不知道怎么换.留 ...
- CM记录-操作系统调优
1.避免使用swap分区---将hadoop守护进程的数据交换到磁盘的行为可能会导致操作超时:物理内存(交换)--Swap分区 2.调整内存分配策略---操作系统内核根据vm.overcommit_m ...
- golang数组声明
格式 初始化数组 {}中的元素数不能大于[]中的数字,并且长度在初始化后不能改变,定义数组时需指定长度 ... var arrName [num]type = [num]type{value, val ...