一、安装
(1)安装Nginx及相关组件
(2)Nginx的路径配置到系统变量中,配完需要重启系统
因查看网站时,http的ResponseHeaders里会有服务器信息,例如:Server:nginx,为了安全,可将服务器信息隐藏掉。1、解压
![](https://img-blog.csdnimg.cn/20200113113811541.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zNjQxNjY4MA==,size_16,color_FFFFFF,t_70)
1、解压
tar -zxvf
unzip nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip
mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42 nginx-goodies-nginx-sticky-module-ng
2、安装PCRE
cd pcre-8.38
./configure
make && make install
3、安装lua模块
cd openresty-1.13.6.2/bundle/LuaJIT-2.1-20180420/
vim /etc/profile
设置root级环境变量
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
source /etc/profile
增加link连接
ln -s /usr/local/lib/libluajit-5.1.so.2 /lib/libluajit-vi5.1.so.2
4、修改nginx源码
4.1. src/http/ngx_http_header_filter_module.c
[sw@swfirstbalance nginx-1.14.0]$ vim src/http/ngx_http_header_filter_module.c
找到:
static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;
修改为:
static u_char ngx_http_server_string[] = "Server: SingleWindow" CRLF;
static u_char ngx_http_server_full_string[] = "Server: SingleWindow" NGINX_VER CRLF;
static u_char ngx_http_server_build_string[] = "Server: SingleWindow" NGINX_VER_BUILD CRLF;
4.2. src/core/nginx.h
[sw@swfirstbalance nginx- 1.14.0]$ vim src/core/nginx.h
找到:
#define NGINX_VERSION " 1.14.0"
#define NGINX_VER "nginx/" NGINX_VERSION
修改为:
#define NGINX_VERSION "x"
#define NGINX_VER "SingleWindow/" NGINX_VERSION
4.3. src/http/ngx_http_special_response.c
[sw@swfirstbalance nginx-1.14.0]$ vim src/http/ngx_http_special_response.c
找到:
static u_char ngx_http_error_tail[] =
"<hr><center>nginx</center>" CRLF
"</body>" CRLF
"</html>" CRLF
修改为:
static u_char ngx_http_error_tail[] =
"<hr><center>SingleWindow</center>" CRLF
"</body>" CRLF
"</html>" CRLF
5、安装nginx
./configure --prefix=/soft/nginx/nginx-1.14.0 \
--with-http_gzip_static_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_realip_module \
--with-pcre=../nginx-other-module/pcre-8.38 \
--with-openssl=../nginx-other-module/openssl-1.0.2p \
--with-zlib=../nginx-other-module/zlib-1.2.11 \
--add-module=../nginx-other-module/nginx-goodies-nginx-sticky-module-ng \
--add-module=../nginx-other-module/nginx_upstream_check_module-0.3.0 \
--add-module=../nginx-other-module/lua-nginx-module-0.10.13 \
make
make install
二、nginx常用命令
1、在sbin目录下
nginx安装路径
nginx启动路径nginx/sbin
(1) nginx 启动nginx
(2)nginx -v 查看nginx版本
(3)nginx -s reload 重新载入配置文件
(4)nginx -s reopen 重启 Nginx
(5)nginx -s stop 停止nginx
(6)nginx安装完成后目录结构
![](https://img-blog.csdnimg.cn/2020011311381567.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zNjQxNjY4MA==,size_16,color_FFFFFF,t_70)
三、常用的第三方模块
1、OpenSSL是一种功能强大的商用级全功能工具包,适用于传输层安全性(TLS)和安全套接字层(SSL)协议。它也是一个通用的加密库。
2、zlib:
一个大型漂亮但又精美不引人注目的压缩库(也是免费的,不提及不受专利限制)
3、lua模块
ngx_lua将Lua嵌入Nginx,可以让Nginx执行Lua脚本,并且高并发、非阻塞的处理各种请求。Lua内建协程,这样就可以很好的将异步回调转换成顺序调用的形式。
4、nginx_upstream_check_module
nginx_upstream_check_module-master 这个就是淘宝技术团队开发的 Nginx 模块 ,通过它可以用来检测后端 realserver 的健康状态。如果后端 realserver 不可用,则所有的请求就不会转发到该节点上。
5、
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。
四、nginx内部模块
nginx模块分为以下几类:
NGX_CORE_MODULE //核心模块
NGX_HTTP_MODULE //HTTP处理模块
NGX_EVENT_MODULE //事件处理模块
NGX_MAIL_MODULE //邮件处理模块