Skip to content

Commit ad333b6

Browse files
drewkhourymarijnh
authored andcommitted
[nginx mode] Add
1 parent 36826c2 commit ad333b6

File tree

2 files changed

+330
-0
lines changed

2 files changed

+330
-0
lines changed

mode/nginx/index.html

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>CodeMirror: NGINX mode</title>
5+
<link rel="stylesheet" href="../../lib/codemirror.css">
6+
<script src="../../lib/codemirror.js"></script>
7+
<script src="nginx.js"></script>
8+
<style>.CodeMirror {background: #f8f8f8;}</style>
9+
<link rel="stylesheet" href="../../doc/docs.css">
10+
</head>
11+
12+
<style>
13+
body {
14+
margin: 0em auto;
15+
}
16+
17+
.CodeMirror, .CodeMirror-scroll {
18+
height: 600px;
19+
}
20+
</style>
21+
22+
<body>
23+
<h1>CodeMirror: NGINX mode</h1>
24+
<form><textarea id="code" name="code" style="height: 800px;">
25+
server {
26+
listen 173.255.219.235:80;
27+
server_name website.com.au;
28+
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
29+
}
30+
31+
server {
32+
listen 173.255.219.235:443;
33+
server_name website.com.au;
34+
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
35+
}
36+
37+
server {
38+
39+
listen 173.255.219.235:80;
40+
server_name www.website.com.au;
41+
42+
43+
44+
root /data/www;
45+
index index.html index.php;
46+
47+
location / {
48+
index index.html index.php; ## Allow a static html file to be shown first
49+
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
50+
expires 30d; ## Assume all files are cachable
51+
}
52+
53+
## These locations would be hidden by .htaccess normally
54+
location /app/ { deny all; }
55+
location /includes/ { deny all; }
56+
location /lib/ { deny all; }
57+
location /media/downloadable/ { deny all; }
58+
location /pkginfo/ { deny all; }
59+
location /report/config.xml { deny all; }
60+
location /var/ { deny all; }
61+
62+
location /var/export/ { ## Allow admins only to view export folder
63+
auth_basic "Restricted"; ## Message shown in login window
64+
auth_basic_user_file /rs/passwords/testfile; ## See /etc/nginx/htpassword
65+
autoindex on;
66+
}
67+
68+
location /. { ## Disable .htaccess and other hidden files
69+
return 404;
70+
}
71+
72+
location @handler { ## Magento uses a common front handler
73+
rewrite / /index.php;
74+
}
75+
76+
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
77+
rewrite ^/(.*.php)/ /$1 last;
78+
}
79+
80+
location ~ \.php$ {
81+
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
82+
83+
fastcgi_pass 127.0.0.1:9000;
84+
fastcgi_index index.php;
85+
fastcgi_param PATH_INFO $fastcgi_script_name;
86+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
87+
include /rs/confs/nginx/fastcgi_params;
88+
}
89+
90+
}
91+
92+
93+
server {
94+
95+
listen 173.255.219.235:443;
96+
server_name website.com.au www.website.com.au;
97+
98+
root /data/www;
99+
index index.html index.php;
100+
101+
ssl on;
102+
ssl_certificate /rs/ssl/ssl.crt;
103+
ssl_certificate_key /rs/ssl/ssl.key;
104+
105+
ssl_session_timeout 5m;
106+
107+
ssl_protocols SSLv2 SSLv3 TLSv1;
108+
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
109+
ssl_prefer_server_ciphers on;
110+
111+
112+
113+
location / {
114+
index index.html index.php; ## Allow a static html file to be shown first
115+
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
116+
expires 30d; ## Assume all files are cachable
117+
}
118+
119+
## These locations would be hidden by .htaccess normally
120+
location /app/ { deny all; }
121+
location /includes/ { deny all; }
122+
location /lib/ { deny all; }
123+
location /media/downloadable/ { deny all; }
124+
location /pkginfo/ { deny all; }
125+
location /report/config.xml { deny all; }
126+
location /var/ { deny all; }
127+
128+
location /var/export/ { ## Allow admins only to view export folder
129+
auth_basic "Restricted"; ## Message shown in login window
130+
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
131+
autoindex on;
132+
}
133+
134+
location /. { ## Disable .htaccess and other hidden files
135+
return 404;
136+
}
137+
138+
location @handler { ## Magento uses a common front handler
139+
rewrite / /index.php;
140+
}
141+
142+
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
143+
rewrite ^/(.*.php)/ /$1 last;
144+
}
145+
146+
location ~ .php$ { ## Execute PHP scripts
147+
if (!-e $request_filename) { rewrite /index.php last; } ## Catch 404s that try_files miss
148+
149+
fastcgi_pass 127.0.0.1:9000;
150+
fastcgi_index index.php;
151+
fastcgi_param PATH_INFO $fastcgi_script_name;
152+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
153+
include /rs/confs/nginx/fastcgi_params;
154+
155+
fastcgi_param HTTPS on;
156+
}
157+
158+
}
159+
160+
</textarea></form>
161+
<script>
162+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
163+
</script>
164+
165+
<p><strong>MIME types defined:</strong> <code>text/nginx</code>.</p>
166+
167+
</body>
168+
</html>

mode/nginx/nginx.js

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
CodeMirror.defineMode("nginx", function(config) {
2+
3+
function words(str) {
4+
var obj = {}, words = str.split(" ");
5+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
6+
return obj;
7+
}
8+
9+
var keywords = words(
10+
/* ngxDirectiveControl */ "break return rewrite set" +
11+
/* ngxDirective */ " accept_mutex accept_mutex_delay access_log add_after_body add_before_body add_header addition_types aio alias allow ancient_browser ancient_browser_value auth_basic auth_basic_user_file auth_http auth_http_header auth_http_timeout autoindex autoindex_exact_size autoindex_localtime charset charset_types client_body_buffer_size client_body_in_file_only client_body_in_single_buffer client_body_temp_path client_body_timeout client_header_buffer_size client_header_timeout client_max_body_size connection_pool_size create_full_put_path daemon dav_access dav_methods debug_connection debug_points default_type degradation degrade deny devpoll_changes devpoll_events directio directio_alignment empty_gif env epoll_events error_log eventport_events expires fastcgi_bind fastcgi_buffer_size fastcgi_buffers fastcgi_busy_buffers_size fastcgi_cache fastcgi_cache_key fastcgi_cache_methods fastcgi_cache_min_uses fastcgi_cache_path fastcgi_cache_use_stale fastcgi_cache_valid fastcgi_catch_stderr fastcgi_connect_timeout fastcgi_hide_header fastcgi_ignore_client_abort fastcgi_ignore_headers fastcgi_index fastcgi_intercept_errors fastcgi_max_temp_file_size fastcgi_next_upstream fastcgi_param fastcgi_pass_header fastcgi_pass_request_body fastcgi_pass_request_headers fastcgi_read_timeout fastcgi_send_lowat fastcgi_send_timeout fastcgi_split_path_info fastcgi_store fastcgi_store_access fastcgi_temp_file_write_size fastcgi_temp_path fastcgi_upstream_fail_timeout fastcgi_upstream_max_fails flv geoip_city geoip_country google_perftools_profiles gzip gzip_buffers gzip_comp_level gzip_disable gzip_hash gzip_http_version gzip_min_length gzip_no_buffer gzip_proxied gzip_static gzip_types gzip_vary gzip_window if_modified_since ignore_invalid_headers image_filter image_filter_buffer image_filter_jpeg_quality image_filter_transparency imap_auth imap_capabilities imap_client_buffer index ip_hash keepalive_requests keepalive_timeout kqueue_changes kqueue_events large_client_header_buffers limit_conn limit_conn_log_level limit_rate limit_rate_after limit_req limit_req_log_level limit_req_zone limit_zone lingering_time lingering_timeout lock_file log_format log_not_found log_subrequest map_hash_bucket_size map_hash_max_size master_process memcached_bind memcached_buffer_size memcached_connect_timeout memcached_next_upstream memcached_read_timeout memcached_send_timeout memcached_upstream_fail_timeout memcached_upstream_max_fails merge_slashes min_delete_depth modern_browser modern_browser_value msie_padding msie_refresh multi_accept open_file_cache open_file_cache_errors open_file_cache_events open_file_cache_min_uses open_file_cache_valid open_log_file_cache output_buffers override_charset perl perl_modules perl_require perl_set pid pop3_auth pop3_capabilities port_in_redirect postpone_gzipping postpone_output protocol proxy proxy_bind proxy_buffer proxy_buffer_size proxy_buffering proxy_buffers proxy_busy_buffers_size proxy_cache proxy_cache_key proxy_cache_methods proxy_cache_min_uses proxy_cache_path proxy_cache_use_stale proxy_cache_valid proxy_connect_timeout proxy_headers_hash_bucket_size proxy_headers_hash_max_size proxy_hide_header proxy_ignore_client_abort proxy_ignore_headers proxy_intercept_errors proxy_max_temp_file_size proxy_method proxy_next_upstream proxy_pass_error_message proxy_pass_header proxy_pass_request_body proxy_pass_request_headers proxy_read_timeout proxy_redirect proxy_send_lowat proxy_send_timeout proxy_set_body proxy_set_header proxy_ssl_session_reuse proxy_store proxy_store_access proxy_temp_file_write_size proxy_temp_path proxy_timeout proxy_upstream_fail_timeout proxy_upstream_max_fails random_index read_ahead real_ip_header recursive_error_pages request_pool_size reset_timedout_connection resolver resolver_timeout rewrite_log rtsig_overflow_events rtsig_overflow_test rtsig_overflow_threshold rtsig_signo satisfy secure_link_secret send_lowat send_timeout sendfile sendfile_max_chunk server_name_in_redirect server_names_hash_bucket_size server_names_hash_max_size server_tokens set_real_ip_from smtp_auth smtp_capabilities smtp_client_buffer smtp_greeting_delay so_keepalive source_charset ssi ssi_ignore_recycled_buffers ssi_min_file_chunk ssi_silent_errors ssi_types ssi_value_length ssl ssl_certificate ssl_certificate_key ssl_ciphers ssl_client_certificate ssl_crl ssl_dhparam ssl_engine ssl_prefer_server_ciphers ssl_protocols ssl_session_cache ssl_session_timeout ssl_verify_client ssl_verify_depth starttls stub_status sub_filter sub_filter_once sub_filter_types tcp_nodelay tcp_nopush thread_stack_size timeout timer_resolution types_hash_bucket_size types_hash_max_size underscores_in_headers uninitialized_variable_warn use user userid userid_domain userid_expires userid_mark userid_name userid_p3p userid_path userid_service valid_referers variables_hash_bucket_size variables_hash_max_size worker_connections worker_cpu_affinity worker_priority worker_processes worker_rlimit_core worker_rlimit_nofile worker_rlimit_sigpending worker_threads working_directory xclient xml_entities xslt_stylesheet xslt_typesdrew@li229-23"
12+
);
13+
14+
var keywords_block = words(
15+
/* ngxDirectiveBlock */ "http mail events server types location upstream charset_map limit_except if geo map"
16+
);
17+
18+
var keywords_important = words(
19+
/* ngxDirectiveImportant */ "include root server server_name listen internal proxy_pass memcached_pass fastcgi_pass try_files"
20+
);
21+
22+
var indentUnit = config.indentUnit, type;
23+
function ret(style, tp) {type = tp; return style;}
24+
25+
function tokenBase(stream, state) {
26+
27+
28+
stream.eatWhile(/[\w\$_]/);
29+
30+
var cur = stream.current();
31+
32+
33+
if (keywords.propertyIsEnumerable(cur)) {
34+
return "keyword";
35+
}
36+
else if (keywords_block.propertyIsEnumerable(cur)) {
37+
return "variable-2";
38+
}
39+
else if (keywords_important.propertyIsEnumerable(cur)) {
40+
return "string-2";
41+
}
42+
/**/
43+
44+
var ch = stream.next();
45+
if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());}
46+
else if (ch == "/" && stream.eat("*")) {
47+
state.tokenize = tokenCComment;
48+
return tokenCComment(stream, state);
49+
}
50+
else if (ch == "<" && stream.eat("!")) {
51+
state.tokenize = tokenSGMLComment;
52+
return tokenSGMLComment(stream, state);
53+
}
54+
else if (ch == "=") ret(null, "compare");
55+
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
56+
else if (ch == "\"" || ch == "'") {
57+
state.tokenize = tokenString(ch);
58+
return state.tokenize(stream, state);
59+
}
60+
else if (ch == "#") {
61+
stream.skipToEnd();
62+
return ret("comment", "comment");
63+
}
64+
else if (ch == "!") {
65+
stream.match(/^\s*\w*/);
66+
return ret("keyword", "important");
67+
}
68+
else if (/\d/.test(ch)) {
69+
stream.eatWhile(/[\w.%]/);
70+
return ret("number", "unit");
71+
}
72+
else if (/[,.+>*\/]/.test(ch)) {
73+
return ret(null, "select-op");
74+
}
75+
else if (/[;{}:\[\]]/.test(ch)) {
76+
return ret(null, ch);
77+
}
78+
else {
79+
stream.eatWhile(/[\w\\\-]/);
80+
return ret("variable", "variable");
81+
}
82+
}
83+
84+
function tokenCComment(stream, state) {
85+
var maybeEnd = false, ch;
86+
while ((ch = stream.next()) != null) {
87+
if (maybeEnd && ch == "/") {
88+
state.tokenize = tokenBase;
89+
break;
90+
}
91+
maybeEnd = (ch == "*");
92+
}
93+
return ret("comment", "comment");
94+
}
95+
96+
function tokenSGMLComment(stream, state) {
97+
var dashes = 0, ch;
98+
while ((ch = stream.next()) != null) {
99+
if (dashes >= 2 && ch == ">") {
100+
state.tokenize = tokenBase;
101+
break;
102+
}
103+
dashes = (ch == "-") ? dashes + 1 : 0;
104+
}
105+
return ret("comment", "comment");
106+
}
107+
108+
function tokenString(quote) {
109+
return function(stream, state) {
110+
var escaped = false, ch;
111+
while ((ch = stream.next()) != null) {
112+
if (ch == quote && !escaped)
113+
break;
114+
escaped = !escaped && ch == "\\";
115+
}
116+
if (!escaped) state.tokenize = tokenBase;
117+
return ret("string", "string");
118+
};
119+
}
120+
121+
return {
122+
startState: function(base) {
123+
return {tokenize: tokenBase,
124+
baseIndent: base || 0,
125+
stack: []};
126+
},
127+
128+
token: function(stream, state) {
129+
if (stream.eatSpace()) return null;
130+
var style = state.tokenize(stream, state);
131+
132+
var context = state.stack[state.stack.length-1];
133+
if (type == "hash" && context == "rule") style = "atom";
134+
else if (style == "variable") {
135+
if (context == "rule") style = "number";
136+
else if (!context || context == "@media{") style = "tag";
137+
}
138+
139+
if (context == "rule" && /^[\{\};]$/.test(type))
140+
state.stack.pop();
141+
if (type == "{") {
142+
if (context == "@media") state.stack[state.stack.length-1] = "@media{";
143+
else state.stack.push("{");
144+
}
145+
else if (type == "}") state.stack.pop();
146+
else if (type == "@media") state.stack.push("@media");
147+
else if (context == "{" && type != "comment") state.stack.push("rule");
148+
return style;
149+
},
150+
151+
indent: function(state, textAfter) {
152+
var n = state.stack.length;
153+
if (/^\}/.test(textAfter))
154+
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
155+
return state.baseIndent + n * indentUnit;
156+
},
157+
158+
electricChars: "}"
159+
};
160+
});
161+
162+
CodeMirror.defineMIME("text/nginx", "nginx");

0 commit comments

Comments
 (0)