魔改编译安装 nginx。
要做啥
如图所示:
希望将 nginx 默认的 错误页面自定义加入一个 返回的超链接。
改源码
下载源码,
http://nginx.org/en/download.html
选择 Stable version, nginx-1.14.0。修改源码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31vim nginx-1.14.0/src/http/ngx_http_special_response.c
# 大约 109 行开始
static char ngx_http_error_401_page[] =
"<html>" CRLF
"<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>401 Authorization Required</title></head>" CRLF
"<body bgcolor=\"white\">" CRLF
"<center><h1>401 Authorization Required</h1></center>" CRLF
"<center><h2><a href=\"/index.html\">返回首页</a></h2></center>" CRLF
;
static char ngx_http_error_402_page[] =
"<html>" CRLF
"<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>402 Payment Required</title></head>" CRLF
"<body bgcolor=\"white\">" CRLF
"<center><h1>402 Payment Required</h1></center>" CRLF
"<center><h2><a href=\"/index.html\">返回首页</a></h2></center>" CRLF
;
static char ngx_http_error_403_page[] =
"<html>" CRLF
"<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>403 Forbidden</title></head>" CRLF
"<body bgcolor=\"white\">" CRLF
"<center><h1>403 Forbidden</h1></center>" CRLF
"<center><h2><a href=\"/index.html\">返回首页</a></h2></center>" CRLF
.
.
.
按自己需求修改,其中,包含中文不要指定 utf-8 编码。
编译
1 | cd nginx-1.14.0 |
各个模块具体用处,请参看以下文章。
添加 service
系统 mint, 对 ubuntu 应该都有效.
1 | vim /etc/init.d/nginx |
记得改权限.
上面的 nginx 路径需要改成自己编译时候写的,或者 which nginx
.
1 | sudo update-rc.d nginx defaults |
参考文档.