Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Generate configuration files for apache and nginx #141

Closed
wants to merge 80 commits into from
Closed
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
a195823
generate-configuration: work in progress
oschaaf Dec 28, 2012
1e0125b
generate-configuration: save some work
oschaaf Dec 28, 2012
8d84add
generate-configuration: save some work
oschaaf Dec 29, 2012
de9fcbf
generate-configuration: save some work
oschaaf Dec 30, 2012
bd4cbc9
generate-configuration: save some work
oschaaf Dec 30, 2012
2b2054f
generate-configuration: handle pagespeed on/off directive
oschaaf Dec 30, 2012
a76d40c
generate-configuration: handle all conditionall pagespeed directives
oschaaf Dec 30, 2012
1ba7d29
generate-configuration: rewrite coverage into generic config
oschaaf Dec 30, 2012
05a057c
generate-configuration: improve output indentation for conditional lines
oschaaf Dec 31, 2012
4fcccff
generate-configuration: rewrite the remaining virtual hosts
oschaaf Dec 31, 2012
6eee743
generate-configuration: remove global listen directives in nginx output
oschaaf Dec 31, 2012
2298035
generate-configuration: 'inherit' locations/directory directives in n…
oschaaf Dec 31, 2012
2158e66
generate-configuration: clean up
oschaaf Dec 31, 2012
44d6228
generate-configuration: work on pagespeed.debug.pyconf, list todo's
oschaaf Jan 1, 2013
58b1a23
generate-configuration: gzip,ssl,headers,etc
oschaaf Jan 2, 2013
a7df405
generate-configuration: modules, header actions
oschaaf Jan 3, 2013
ce9e5d1
generate-configuration: mime-types, apache specific literals, make so…
oschaaf Jan 6, 2013
15f14d0
generate-configuration: merge directory sections w. the same path
oschaaf Jan 6, 2013
ba51472
generate-configuration: merge 2 mod_pagespeed_example/ directory sect…
oschaaf Jan 6, 2013
3bb5933
generate-configuration: add more apache-specific literals
oschaaf Jan 6, 2013
25a933a
generate-configuration: handle proxy_pass
oschaaf Jan 6, 2013
2c90fac
generate-configuration: handle options, rewrite rules
oschaaf Jan 7, 2013
8e54ff3
generate-configuration: add temporary locations to force pagespeed ha…
oschaaf Jan 7, 2013
352e1ea
generate-configuration: style changes
oschaaf Jan 8, 2013
7a5b0fe
generate-configuration: require mime/pagespeed modules
oschaaf Jan 9, 2013
67f25cb
generate-configuration: make httpd parse the output OK
oschaaf Jan 9, 2013
93b57c1
generate-configuration: add lost filecachepaths
oschaaf Jan 9, 2013
07f7c53
generate-configuration: add lost filecachepaths
oschaaf Jan 9, 2013
82e17a9
generate-configuration: changes after first tests
oschaaf Jan 9, 2013
4ce45e9
Merge branch 'master' of https://github.com/pagespeed/ngx_pagespeed i…
oschaaf Jan 9, 2013
184caf9
generate-configuration: improve preprocessing
oschaaf Jan 9, 2013
22c0f9f
generate-configuration: make nginx's configuration test pass
oschaaf Jan 9, 2013
0f0f9c9
generate-configuration: save state
oschaaf Jan 9, 2013
6113f96
load-from-file: save work before switch branch
oschaaf Jan 11, 2013
c0dcd86
generate-confgiguration: handle unarysub in pagespeed.pyconf
oschaaf Jan 14, 2013
bdee9e6
Merge branch 'master' of https://github.com/pagespeed/ngx_pagespeed i…
oschaaf Jan 15, 2013
ae9cc6f
generate-confgiguration: merge header directives in locations
oschaaf Jan 16, 2013
f70c4c6
generate-confgiguration: changes after testing apache/nginx outputs
oschaaf Jan 17, 2013
6f40368
generate-confgiguration: cleanup pagespeed.debug.pyconf
oschaaf Jan 17, 2013
4932393
generate-configuration: apache ssl
oschaaf Jan 18, 2013
081a43b
generate-configuration: cosmetic changes
oschaaf Jan 21, 2013
993a578
generate-configuration: whitespace
oschaaf Jan 21, 2013
ffe5090
generate-configuration: style fixes
oschaaf Jan 21, 2013
9077d19
generate-configuration: more style fixes
oschaaf Jan 21, 2013
ca089cd
generate-configuration: remove directories directive handling
oschaaf Jan 21, 2013
0ae7619
generate-configuration: whitespace formatting in templates
oschaaf Jan 21, 2013
b0b901c
generate-configuration: strip unused helpers
oschaaf Jan 21, 2013
d69ffa9
generate-configuration: more formatting
oschaaf Jan 21, 2013
b27e813
generate-configuration: process todo's in comments
oschaaf Jan 21, 2013
ff0e5ec
generate-configuration: save state
oschaaf Jan 21, 2013
08a6b3a
generate-configuration: add license banner, consolidate todo's from code
oschaaf Jan 21, 2013
666aead
generate-configuration: work through todo list
oschaaf Jan 21, 2013
41e3c61
generate-configuration: add license banners in templates
oschaaf Jan 21, 2013
7d83725
generate-configuration: improve indent method, style changes
oschaaf Jan 22, 2013
41ed326
generate-configuration: update location handling
oschaaf Jan 22, 2013
7101a7f
generate-configuration: don't hardcode input .pyconf file
oschaaf Jan 22, 2013
b365a09
generate-configuration: update todo's
oschaaf Jan 22, 2013
87fda3a
generate-configuration: process ngx_system_test.sh results
oschaaf Jan 22, 2013
3964a73
Merge remote-tracking branch 'origin/master' into oschaaf-generate-co…
oschaaf Jan 22, 2013
1f67dd5
Update README.md
oschaaf Jan 22, 2013
00418b0
extend prefix format; use fewer ifdefs and more prefixes
jeffkaufman Feb 12, 2013
e100ce0
Merge pull request #168 from pagespeed/jefftk-generate-config-terser
jeffkaufman Feb 12, 2013
f651972
generate-configuration: comment style
oschaaf Feb 12, 2013
cb26cb1
generate-configuration: remove parens in print statement
oschaaf Feb 12, 2013
f1da39e
fix some template errors
jeffkaufman Feb 12, 2013
6de3391
generate-configuration: correct script name in print statement
oschaaf Feb 12, 2013
2ce6747
generate-configuration: doc mode argument use in cli ouput
oschaaf Feb 12, 2013
54f3560
Merge pull request #169 from pagespeed/jefftk-generate-config-verific…
jeffkaufman Feb 12, 2013
959272e
generate-config: move ALL_DIRECTIVES to a separate vhost
oschaaf Feb 12, 2013
1d5755b
generate-config: restore apache conditions
oschaaf Feb 12, 2013
ea4582f
Merge pull request #171 from pagespeed/oschaaf-generate-config-all-di…
jeffkaufman Feb 12, 2013
455a9bb
generate-config: display line numbers in errors
oschaaf Feb 13, 2013
b680348
generate-config: line numbers in error messages
oschaaf Feb 13, 2013
58ec586
generate-config: tidy up
oschaaf Feb 13, 2013
a22f1f8
Merge pull request #172 from pagespeed/oschaaf-generate-config-linenu…
jeffkaufman Feb 13, 2013
c7ddfca
generate-config: make the nginx template filter unsupported directives
oschaaf Feb 14, 2013
dc97039
generate-config: make unsupported directive functionality available t…
oschaaf Feb 14, 2013
1e85d57
Revert "generate-config: make unsupported directive functionality ava…
oschaaf Feb 14, 2013
8083e10
generate-config: don't mix tabs and spaces
oschaaf Feb 14, 2013
46e1e48
Merge pull request #174 from pagespeed/oschaaf-generate-config-unsupp…
jeffkaufman Feb 14, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Expand Up @@ -138,7 +138,7 @@ urls being replaced with new ones like `yellow.css.pagespeed.ce.lzJ8VcVi1l.css`.

### Testing

The generic Pagespeed system test is ported, and all but three tests pass. To
The generic Pagespeed system test is ported, and all but six tests pass. To
run it you need to first build and configure nginx. Set it up something like:

...
Expand Down Expand Up @@ -206,7 +206,20 @@ run it you need to first build and configure nginx. Set it up something like:
}
}

Then run the test, using the port you set up with `listen` in the configuration
Alternatively, you can also generate a configuration file using

cd /path/to/ngx_pagespeed/test/genconf/
# TODO(oschaaf): which directive do we supply here?
./cli.py pagespeed.debug.pyconf nginx FOO > test.nginx.conf

This will currently set up nginx to listen on localhost:8083

After configuring, you can proceed to start nginx with this generated
configuration like

/path/to/nginx_executable/nginx -t -c test.nginx.conf

To run the test, using the port you set up with `listen` in the configuration
file:

/path/to/ngx_pagespeed/test/nginx_system_test.sh localhost:8050
Expand All @@ -219,8 +232,12 @@ This should print out a lot of lines like:
and then eventually:

Failing Tests:
In-place resource optimization
In-place resource optimization
add_instrumentation adds 2 script tags
compression is enabled for rewritten JS.
convert_meta_tags
rewrite_javascript,inline_javascript with gzipped js origin
insert_dns_prefetch
insert_dns_prefetch
FAIL.
Expand Down
203 changes: 203 additions & 0 deletions test/genconf/apache.conf.template
@@ -0,0 +1,203 @@
${
# Copyright 2013 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: oschaaf@gmail.com (Otto van der Schaaf)

from util import *

set_writer(emit)

def write_servers_open_item(server,level):
emit_indent("<VirtualHost %s:%s>\n" % (server["address"], server["port"])
, level)
if "root" in server:
emit_indent("DocumentRoot %s\n" % server["root"], level+1)
if "server_name" in server:
emit_indent("ServerName %s\n" % server["server_name"], level+1)
if "pagespeed_status" in server:
emit_indent("ModPagespeed %s\n" % server["pagespeed_status"], level+1)

def write_servers_close_item(server,level):
emit_indent("</VirtualHost>\n",level)

def write_locations_open_item(server,level):
if "path" in server:
emit_indent("<Location ~ \"%s\">\n" % server["path"],level)

if "proxy_pass" in server:
emit_indent("ProxyPass %s\n" % server["proxy_pass"],level+1)

def write_locations_close_item(server,level):
emit_indent("</Location>\n",level)

def write_pagespeed_open(ps,level):
for key in ps:
val = ps[key]
# in pagespeed.debug.conf, the same pagespeed directive can occur
# multiple times that is represented as an array, in our config
# which we need to loop in that case
if isinstance(val,list) and not isinstance(val,str):
for item in val:
emit_indent("ModPagespeed%s %s\n" %(key,str(item)),level)
else:
emit_indent("ModPagespeed%s %s\n" % (key, str(val)),level)

return True

def write_pagespeed_if_open(ps,level):
for key in ps:
emit_indent("<ModPagespeedIf %s>\n" % key,level)
val = ps[key]
write_pagespeed_open(val, level+1)
emit_indent("</ModPagespeedIf>\n",level)
return True

def write_pagespeed_if_close(ps,level):
pass

def write_listen_open(ps, level):
for val in ps:
emit_indent("Listen %s\n" % str(val), level)
return True


def write_name_virtual_hosts_open(ps, level):
for val in ps:
emit_indent("NameVirtualHost %s:%s\n" % (val["address"],
str(val["port"])),level)

return True

def write_headers_open(ps, level):
for val in ps:
action = val["action"]
header_name = val["name"]
header_value = val["value"]
emit_indent("Header %s %s %s\n"
% (action, repr(header_name), repr(header_value)),level)

return True

def write_required_modules_open(ps,level):
module_path_prefix = "@@APACHE_MODULES@@/mod_"
for module_name in ps:
load_module = "LoadModule %s_module %s%s.so\n" \
% (module_name, module_path_prefix,module_name)
load_module = indent(load_module, level + 1)

if module_name in ["headers","rewrite"]:
emit_indent("<IfModule !" + module_name + "_module>\n", level)
emit(load_module)
emit_indent("</IfModule>\n",level)
elif module_name == "include":
emit_indent("<IfModule !" + module_name + "_module>\n", level)
emit(load_module)
emit_indent("</IfModule>\n",level)
emit_indent("AddType text/html .shtml\n",level)
emit_indent("AddOutputFilter INCLUDES .shtml\n",level)
elif module_name == "ssl":
emit_indent("Include @@APACHE_SSL_CONF@@\n",level);
emit_indent("<IfModule !" + module_name + "_module>\n", level)
emit(load_module)
emit_indent("</IfModule>\n",level)
emit_indent("SSLRandomSeed startup builtin\n",level)
emit_indent("SSLRandomSeed connect builtin\n",level)
elif module_name == "socache_shmcb":
emit_indent("<IfVersion >= 2.4>\n",level);
emit_indent("<IfModule !" + module_name + "_module>\n", level+1)
emit(load_module)
emit_indent("</IfModule>\n",level+1)
emit_indent("</IfVersion>\n",level)
elif module_name == "slotmem_shm":
emit_indent("<IfVersion >= 2.4>\n",level)
emit_indent("<IfModule !" + module_name + "_module>\n", level+1)
emit(load_module)
emit_indent("</IfModule>\n",level+1)
emit_indent("</IfVersion>\n",level)
elif module_name == "speling":
emit_indent("<IfModule !" + module_name + "_module>\n", level)
emit(load_module)
emit_indent("</IfModule>\n",level)
emit_indent("CheckSpelling on\n",level)
elif module_name == "gzip":
emit_indent("SetOutputFilter DEFLATE\n",level)
elif module_name == "cgi-script":
emit_indent("AddHandler cgi-script .cgi\n",level)
elif module_name == "mime":
emit_indent("<IfModule !" + module_name + "_module>\n", level)
emit(load_module)
emit_indent("</IfModule>\n",level)
elif module_name == "pagespeed":
emit_indent("<IfModule !" + module_name + "_module>\n", level)
emit(load_module)
emit_indent("</IfModule>\n",level)
elif module_name == "proxy":
emit_indent("<IfModule !" + module_name + "_module>\n", level)
emit(load_module)
emit_indent("</IfModule>\n",level)
else:
raise Exception("unknown module: " + module_name)
return True

def write_literal_open(ps, level):
emit(ps["value"])

def write_mime_types_open_item(ps,level):
emit_indent("AddType %s %s\n" % (ps["extension"], ps["mime_type"]),level)

def write_add_options_open(ps,level):
for item in ps:
emit_indent("Options +%s\n" % item , level)
return True

def write_rewrite_rules_open(ps,level):
emit_indent("RewriteEngine on\n",level)
for item in ps:
emit_indent("RewriteRule %s %s\n"
% (item["pattern"], item["substitution"]),level)
return True

key_to_writer = {
"defaults_open": write_void,
"defaults_close": write_void,
"servers_open": write_void,
"servers_close": write_void,
"servers_open_item": write_servers_open_item,
"servers_close_item": write_servers_close_item,
"locations_open": write_void,
"locations_close": write_void,
"locations_open_item": write_locations_open_item,
"locations_close_item": write_locations_close_item,
"pagespeed_open": write_pagespeed_open,
"pagespeed_close": write_void,
"pagespeed_if_open": write_pagespeed_if_open,
"pagespeed_if_close": write_pagespeed_if_close,
"listen_open": write_listen_open,
"listen_close": write_void,
"name_virtual_hosts_open": write_name_virtual_hosts_open,
"name_virtual_hosts_close": write_void,
"required_modules_open": write_required_modules_open,
"headers_open": write_headers_open,
"mime_types_open": write_void,
"mime_types_open_item": write_mime_types_open_item,
"literal_open": write_literal_open,
"add_options_open": write_add_options_open,
"rewrite_rules_open": write_rewrite_rules_open,
}

}$# @@__template_header@@

${write_cfg(key_to_writer, config)
}$
81 changes: 81 additions & 0 deletions test/genconf/cli.py
@@ -0,0 +1,81 @@
#!/usr/bin/python
# Copyright 2013 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: oschaaf@gmail.com (Otto van der Schaaf)


# configuration generator for pagespeed

import datetime
from genconf import execute_template
import sys
from util import Error

def exit_with_help_message():
print "This script transforms .pyconf files into webserver configuration files"
print "usage: ./genconf.py <input.pyconf> <output_format> <mode>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./cli.py

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffkaufman
corrected in 6de3391

print "where output_format can be either 'apache' or 'nginx'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc what <mode> can be

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quit()

# conditions indicate which conditional configuration sections
# should be included
# formats:
# #CONDITION
# or:
# #ifdef CONDITION
# ....
# #endif
# the output mode ('nginx' or 'apache') is also set as a condition
# to be able to have output specific configuration sections
conditions = {}

# placeholders are inserted into the configuration during preprocessing
# format in templates: @@PLACEHOLDER@@
placeholders = {
'APACHE_SECONDARY_PORT': 8083,
'APACHE_DOMAIN': 'apache.domain',
'APACHE_DOC_ROOT': '/home/oschaaf/code/google/mod_pagespeed/src/install',
'MOD_PAGESPEED_CACHE': '/tmp/psol_cache',
'APACHE_MODULES': '/usr/lib/apache2/modules',
'NGX_CONF_DIRECTORY': '/usr/local/nginx/conf',
'APACHE_SSL_CONF':'/etc/apache2/mods-available/ssl.conf',
'APACHE_HTTPS_DOMAIN': 'localhost',
'MOD_PAGESPEED_STATS_LOG': 'stats.log'
}

input_config_path = ""
output_format = ""
mode = ""

if len(sys.argv) == 4:
input_config_path = sys.argv[1]
output_format = sys.argv[2]
mode = sys.argv[3]
else:
exit_with_help_message()

conditions[mode] = True
conditions[output_format] = True
placeholders["__template_header"] = "generated at %s through \"%s\"" %\
(datetime.datetime.now().strftime('%b-%d-%I%M%p-%G'), ' '.join(sys.argv))

#by convention, a file named <outputformat>.conf.template is
#expected to contain the translation script
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces before comments

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template = output_format + '.conf.template'

text = execute_template(input_config_path, conditions,
placeholders, template)
print(text)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is for python2, which I think it is, no parens needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffkaufman
removed in cb26cb1