-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
145 lines (136 loc) · 4.72 KB
/
default.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package ncserial
import (
"fmt"
"path/filepath"
)
var (
defaultProxyConfig = Options{
{"proxy_redirect", "off"},
{"proxy_set_header", "Host $host"},
{"proxy_set_header", "X-Real-IP $remote_addr"},
{"proxy_set_header", "X-Forwarded-For $proxy_add_x_forwarded_for"},
{"client_max_body_size", "10m"},
{"client_body_buffer_size", "128k"},
{"proxy_connect_timeout", "90"},
{"proxy_send_timeout", "90"},
{"proxy_read_timeout", "90"},
{"proxy_buffers", "32 4k"},
}
defaultFastcgiConfig = Options{
{"fastcgi_param", "SCRIPT_FILENAME $document_root$fastcgi_script_name"},
{"fastcgi_param", "QUERY_STRING $query_string"},
{"fastcgi_param", "REQUEST_METHOD $request_method"},
{"fastcgi_param", "CONTENT_TYPE $content_type"},
{"fastcgi_param", "CONTENT_LENGTH $content_length"},
{"fastcgi_param", "SCRIPT_NAME $fastcgi_script_name"},
{"fastcgi_param", "REQUEST_URI $request_uri"},
{"fastcgi_param", "DOCUMENT_URI $document_uri"},
{"fastcgi_param", "DOCUMENT_ROOT $document_root"},
{"fastcgi_param", "SERVER_PROTOCOL $server_protocol"},
{"fastcgi_param", "GATEWAY_INTERFACE CGI/1.1"},
{"fastcgi_param", "SERVER_SOFTWARE nginx/$nginx_version"},
{"fastcgi_param", "REMOTE_ADDR $remote_addr"},
{"fastcgi_param", "REMOTE_PORT $remote_port"},
{"fastcgi_param", "SERVER_ADDR $server_addr"},
{"fastcgi_param", "SERVER_PORT $server_port"},
{"fastcgi_param", "SERVER_NAME $server_name"},
{"fastcgi_index", "index.php"},
{"fastcgi_param", "REDIRECT_STATUS 200"},
}
defaultMimeTypes = Options{
{"text/html", "html htm shtml"},
{"text/css", "css"},
{"text/xml", "xml rss"},
{"image/gif", "gif"},
{"image/jpeg", "jpeg jpg"},
{"application/x-javascript", "js"},
{"text/plain", "txt"},
{"text/x-component", "htc"},
{"text/mathml", "mml"},
{"image/png", "png"},
{"image/x-icon", "ico"},
{"image/x-jng", "jng"},
{"image/vnd.wap.wbmp", "wbmp"},
{"application/java-archive", "jar war ear"},
{"application/mac-binhex40", "hqx"},
{"application/pdf", "pdf"},
{"application/x-cocoa", "cco"},
{"application/x-java-archive-diff", "jardiff"},
{"application/x-java-jnlp-file", "jnlp"},
{"application/x-makeself", "run"},
{"application/x-perl", "pl pm"},
{"application/x-pilot", "prc pdb"},
{"application/x-rar-compressed", "rar"},
{"application/x-redhat-package-manager", "rpm"},
{"application/x-sea", "sea"},
{"application/x-shockwave-flash", "swf"},
{"application/x-stuffit", "sit"},
{"application/x-tcl", "tcl tk"},
{"application/x-x509-ca-cert", "der pem crt"},
{"application/x-xpinstall", "xpi"},
{"application/zip", "zip"},
{"application/octet-stream", "deb"},
{"application/octet-stream", "bin exe dll"},
{"application/octet-stream", "dmg"},
{"application/octet-stream", "eot"},
{"application/octet-stream", "iso img"},
{"application/octet-stream", "msi msp msm"},
{"audio/mpeg", "mp3"},
{"audio/x-realaudio", "ra"},
{"video/mpeg", "mpeg mpg"},
{"video/quicktime", "mov"},
{"video/x-flv", "flv"},
{"video/x-msvideo", "avi"},
{"video/x-ms-wmv", "wmv"},
{"video/x-ms-asf", "asx asf"},
{"video/x-mng", "mng"},
}
defaultEvents = Events{
WorkerConnections: 204800,
Use: "epoll",
MultiAccept: true,
}
)
// NewDefaultHTTPConfig create default http Config
func NewDefaultHTTPConfig() HTTP {
logformat := "main '$remote_addr - $remote_user [$time_local] $status " +
`"$request" $body_bytes_sent "$http_referer" ` +
`"$http_user_agent" "$http_x_forwarded_for"'`
http := HTTP{
DefalutType: "application/octet-stream",
LogFormat: logformat,
MimeTypes: defaultMimeTypes,
SendFile: true,
ExtConfig: MergeOptions(defaultProxyConfig, defaultFastcgiConfig),
}
return http
}
//NewDefaultRestyConfig create default resty config
func NewDefaultRestyConfig(prefix, logPath, lualibPath string) *Config {
config := &Config{}
config.WorkerProcesses = "auto"
config.LimitNofile = 204800
config.Events = defaultEvents
errorLogPath := filepath.Join(logPath, "error.log")
config.ErrorLog = errorLogPath + " warn"
config.PId = filepath.Join(logPath, "nginx.pid")
config.Extras = Options{
{"env", "RESTY_VERSION"},
{"env", "RESTY_PREFIX"},
}
config.HTTP = NewDefaultHTTPConfig()
config.HTTP.AccessLog = filepath.Join(logPath, "access.log")
config.HTTP.ExtConfig = Options{
{"keepalive_timeout", "60"},
{"lua_socket_connect_timeout", "3s"},
{"lua_socket_send_timeout", "3s"},
{"lua_socket_read_timeout", "3s"},
}
if len(lualibPath) > 0 {
config.HTTP.ExtConfig = append(config.HTTP.ExtConfig,
[]string{"lua_package_path", fmt.Sprintf("'%s/?.lua;%s/?/init.lua;;'", lualibPath, lualibPath)})
config.HTTP.ExtConfig = append(config.HTTP.ExtConfig,
[]string{"lua_package_cpath", fmt.Sprintf("'%s/?.so;;'", lualibPath)})
}
return config
}