Compare commits

...

33 Commits

Author SHA1 Message Date
Otto van der Schaaf 11ba8ea542 Update PSOL_BINARY_URL 2017-11-29 15:31:01 +01:00
Otto van der Schaaf a760c28de8 F_SETPIPE_SZ: check for existence before using (#1505)
Kernels before 2.6.35 do not have F_SETPIPE_SZ defined.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1503
2017-11-29 15:28:21 +01:00
Otto van der Schaaf 01e99fb3ef Fix ngx_pagespeed installing dependency packages (#1498)
- Fix auto-install of required packages by fixing quoting (thanks @jeffkaufman!). 
- Add libuuid-devel for redhat-based distro's too.

Fixes https://github.com/pagespeed/mod_pagespeed/issues/1680
2017-11-29 15:28:11 +01:00
Otto van der Schaaf 93e72cf910 build_ngx_pagespeed.sh: add uuid-dev (#1497) 2017-11-29 15:28:02 +01:00
Otto van der Schaaf 1beaa2efb1 Update PSOL_BINARY_URL
Add a newline, like on branch 34
2017-11-02 22:45:43 +01:00
Otto van der Schaaf 8266c75867 release: version 1.13.35.1 2017-11-01 13:51:05 +01:00
Otto van der Schaaf 8de5d7e443 Update mod_pagespeed to 569affb1a2baef30a34f9df6c2f152897c0fd896 (#1495) 2017-11-01 22:29:10 +01:00
Yukihiko SAWANOBORI 49006858d1 Set buildtype from env PSOL_BUILDTYPE. (#1486) 2017-10-06 11:13:18 +02:00
Otto van der Schaaf 11f67d9bc7 Fix nginx worker 100% cpu usage (spinning on write returning EAGAIN)
Bump the pipe capacity, because running out of buffer space may cause
a write to spin indefinitely on EAGAIN.
Bumping the pipe capacity should eliminate the problem in practice,
though in theory the module could still be subject to it.
For now, leaving behind a todo with a suggested solution (should
the problem ever show up again).

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1380
2017-09-29 09:06:33 +02:00
Otto van der Schaaf 6f94abef67 nginx-1.13.4: use preprocessor define instead of const for comparison (#1483)
Address a mistake I made in https://github.com/pagespeed/ngx_pagespeed/pull/1458

While testing the draft for 1.12.34.3 I noticed that older nginx
versions would fail to compile. Switch kNginx13_1_4 to a #define so we
can use it to properly compare.
2017-09-25 22:56:58 +02:00
PikachuEXE 662c1e1c5a Fix compiling issue with older nginx (#1470) 2017-09-18 07:27:59 +02:00
PikachuEXE a897f64ce8 ! Fix syntax of script (#1469) 2017-09-18 07:27:03 +02:00
Otto van der Schaaf 4d9e5fcb0c Fix ignored return code in ps_simple_handler() (#1468)
Fix for https://github.com/pagespeed/ngx_pagespeed/issues/1465
2017-09-11 21:11:50 +02:00
PikachuEXE 65761a2393 Update build script to pass --skip_deps when called with --no-deps-check (#1461) 2017-08-31 17:53:41 +02:00
Otto van der Schaaf 76500396ff Update mod_pagespeed testing dependency (#1460)
* Update mod_pagespeed testing dependency
(mod_pagespeed commit a7c39a1b5a14f1422fef19e8e9dcb11074ba1c65)
* Add explicit default server{} on secondary_port to so that the recent
tests for css parser improvements land on a vhost with the right filters
enabled.
2017-08-22 16:27:41 +02:00
Otto van der Schaaf ef3899515e Adress @jmarantz his comment from #1453's review (#1458)
PR #1453 was merged too soon, using this PR to address
https://github.com/pagespeed/ngx_pagespeed/pull/1453#discussion_r134222719

(Sorry Josh!)
2017-08-21 21:00:49 +02:00
Otto van der Schaaf c67f664244 nginx 1.13.4: Fix compilation error (#1453)
* Compilation of ngx_pagespeed broke with the following commit in
nginx: https://github.com/nginx/nginx/commit/129b06dc5dfab7b4513a4f274b3778cd9b8a6a22
This change intends to unbreak it while maintaining backwards
compatibility.

* updates the nginx testing-dependency to 1.13.4

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1451
2017-08-21 12:25:50 +02:00
Otto van der Schaaf 54847f6d1d point mod_pagespeed submodule to the latest rev (#1433)
* point mod_pagespeed submodule to the latest rev
* Add missing vhost for test "Image rewrite with flush"
2017-06-27 23:53:31 +02:00
Otto van der Schaaf 5631800479 Don't respond with an entitybody to HEAD requests for html (#1376)
Mind r->header_only when processing the response body.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1375
2017-02-07 12:02:43 +01:00
Jeff Kaufman a7d1f91dc3 standby: add standby mode (#1365)
* standby: add standby mode

Add standby mode for ngx_pagespeed, equivalent to "off" in mod_pagespeed.

With this change "off" is deprecated, and people should use "unplugged" instead.

* Update mps to include test file

* update mps

* update mps

* update mps
2017-01-25 13:24:15 -05:00
Jeff Kaufman 61b949c5e5 devel: simplify ngx_pagespeed development flow (#1363)
* provide scripts/rebuild.sh so you don't have to run make commands in
  two directories
* make test/run_tests.sh able to run with no arguments by setting good defaults.
2017-01-20 09:29:34 -05:00
Jeff Kaufman 5b307745ce fix TEST_TO_RUN in ngx_pagespeed (#1364)
Eventually we'll convert remote_config_system_test.sh and nginx_system_test.sh
to use run_test, but until then when TEST_TO_RUN is specified we should skip
the tests in those files and just run system/system_test.sh
2017-01-20 09:28:54 -05:00
Jeff Kaufman f78058b6c4 Allow use of "unplugged" without crashing (#1362)
* update mps

* stop crashing when unplugged

* formatting fixes
2017-01-19 13:48:01 -05:00
Jeff Kaufman 8a0b080229 install: add --additional-nginx-configure-arguments option (#1344)
Instead of requiring people to answer a prompt to specify which additional
arguments they would like nginx to be built with, allow people to specify
arguments like this on the command line.  The quoting is not ideal, since
it's important to pass spaces etc properly all the way through to the
underlying commands, but I give an example in the help text.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1340
2017-01-03 07:07:50 -05:00
Jeff Kaufman cb56136fe1 travis: send emails to new pagespeed-ci group instead of individual devs (#1341) 2016-12-19 13:45:56 -05:00
Jeff Kaufman a4ac43e4d4 travis: get it building and passing tests (#1339)
* travis: get it building and passing tests

I initially planned to get this working on Ubuntu 12, but decided it wasn't
worth it and switched to Ubuntu 14 (Trusty).  Now it passes tests on Travis, so
I've added other people's emails back to the set of people to send emails to.

Also update mps while we're at it.

* update mps

* update mps

* ngx_pagespeed depends on luuid

* update mps
2016-12-19 13:21:33 -05:00
Jeff Kaufman 80c4b7e97b config: use Release binaries when building with --with-debug if that's all that's available (#1332)
* config: use Release binaries when building with --with-debug if that's all that's available

* prompt the user before going ahead and using release binaries

* exit 1, reword message
2016-12-14 10:13:45 -05:00
Jeff Kaufman 0c7d64221c licensing: correct bash license comments (#1336)
A few bash files were missing license comments
2016-12-12 13:40:41 -05:00
Jeff Kaufman 68185b8605 installer: allow --dynamic-module to be used with tags (#1334)
* installer: allow --dynamic-module to be used with tags

A user-friendly check with dynamic module building tries to warn people early if the version of ngx_pagespeed they're building is too old to be compiled as a dynamic module, but this can't work with tags.  If we're given something other than a numeric version number, don't try to perform this check.

Fixes https://github.com/pagespeed/mod_pagespeed/issues/1443
2016-12-08 15:14:12 -05:00
hillsp 7f225e2e70 Add format_binary_url.sh (#1331) 2016-12-06 13:16:29 -05:00
Jeff Kaufman 4d728fc081 branch-names: now that trunk-tracking is master, update references (#1330) 2016-12-06 12:01:50 -05:00
hillsp a399e04a00 Delete prepare_psol.sh (#1310)
Replaced with install/build_psol.sh  in mod_pagespeed.
2016-12-06 11:43:13 -05:00
Jeff Kaufman 247a821564 install: add support for building psol from source and setting up for development (#1313)
* adds support for `--psol-from-source` so you don't need binary modules, and `--devel` so you can run our tests without going and getting all our dependencies
* adds submodules for testing: mod_pagespeed, ngx_cache_purge etc
* adds support for running as:
```
git clone git@github.com:pagespeed/ngx_pagespeed.git
cd ngx_pagespeed/
git checkout <branch>
scripts/build_ngx_pagespeed.sh [options]
```
* depends on the scripts @hillsp is working on so that we can just check out mod_pagespeed and ask it to build and rebuild itself
* adds colors to output to make it easier to read
2016-12-06 09:21:42 -05:00
17 changed files with 691 additions and 288 deletions
+1
View File
@@ -2,3 +2,4 @@ test/tmp
psol/
psol-*.tar.gz
*.*.*.*.tar.gz
nginx
View File
+25 -42
View File
@@ -1,50 +1,33 @@
language: c++
env:
global:
- MAKEFLAGS=-j3
# By default travis loads submodules serially, but we can load them in parallel
# if we install an updated git and use --jobs. Some timing numbers:
# serial: 257s
# jobs=4: 182s (29s to install new git, 153s to run the downloads)
# jobs=8: 179s (29s to install new git, 150s to run the downloads)
# We can't use --depth=1, though, because github doesn't have
# allowReachableSHA1InWant set.
#
# TODO(jefftk): once we're running on a server with git 2.8 or later we can have
# --jobs without installing a new git.
git:
submodules: false
before_install:
- sudo add-apt-repository --yes ppa:git-core/ppa
- sudo apt-get update
- sudo apt-get install git
- git submodule update --init --recursive --jobs=8
install:
- mv $TRAVIS_BUILD_DIR ~/ngxpagespeed
- sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip g++ python gperf make devscripts fakeroot git curl netcat-traditional gcc-mozilla clang-3.4 2>&1 > /dev/null
- export PATH=/usr/lib/gcc-mozilla/bin:$PATH
- sudo ln -sf /usr/lib/gcc-mozilla/lib/libstdc++.so.6 /usr/lib/x86_64-linux-gnu/libstdc++.so.6
# - sudo sh -c 'echo "image/webp webp" >> /etc/mime.types'
# - mkdir -p ~/bin
# - cd ~/bin
# - git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
- mkdir ~/mod_pagespeed
- cd ~/mod_pagespeed
- git clone --recursive https://github.com/pagespeed/mod_pagespeed.git src
- cd src
- python build/gyp_chromium --depth=.
- cd ~/mod_pagespeed/src/pagespeed/automatic
- make BUILDTYPE=Release -C ../../pagespeed/automatic all
- cd ~
- git clone https://github.com/FRiCKLE/ngx_cache_purge.git
- NGX_CACHE_PURGE=$PWD/ngx_cache_purge
- wget https://openresty.org/download/ngx_openresty-1.9.7.2.tar.gz
- tar xzf ngx_openresty-*.tar.gz
- cd ngx_openresty-*/
- ./configure --with-luajit
- make
- NGX_DEVEL_KIT=$(echo $HOME/ngx_openresty-*/build/ngx_devel_kit-*/)
- SET_MISC_MODULE=$(echo $HOME/ngx_openresty-*/build/set-misc-nginx-module-*/)
- HEADERS_MORE_MODULE=$(echo $HOME/ngx_openresty-*/build/headers-more-nginx-module-*/)
- cd ~
- wget https://github.com/nginx/nginx/archive/branches/default.zip
- unzip default.zip
- cd nginx-branches-default
- MOD_PAGESPEED_DIR="$HOME/mod_pagespeed/src" ./auto/configure --add-module=$HOME/ngxpagespeed --add-module="$NGX_CACHE_PURGE" --add-module="$NGX_DEVEL_KIT" --add-module="$SET_MISC_MODULE" --add-module="$HEADERS_MORE_MODULE" --with-ipv6
- make
- sudo make install
scripts/build_ngx_pagespeed.sh --devel --assume-yes
script:
- echo "build successful"
- echo "cd ~/ngxpagespeed"
- echo "sudo ./test/run_tests.sh $HOME/mod_pagespeed $HOME/nginx-branches-default/objs/nginx"
test/run_tests.sh $PWD/testing-dependencies/mod_pagespeed/ \
$PWD/nginx/sbin/nginx
dist: trusty
sudo: required
compiler:
- gcc
notifications:
email:
- cheesy@google.com
- jefftk@google.com
- morlovich@google.com
- jmarantz@google.com
- huibao@google.com
- jcrowell@google.com
- pagespeed-ci@googlegroups.com
+1 -4
View File
@@ -1,4 +1 @@
In a release this file would contain the URL to download the pre-compiled PSOL
binary, but on development branches (like this one) you have to build PSOL from
source yourself. See:
https://github.com/pagespeed/ngx_pagespeed/wiki/Building-PSOL-From-Source
https://dl.google.com/dl/page-speed/psol/1.13.35.2-$BIT_SIZE_NAME.tar.gz
+1 -1
View File
@@ -1,6 +1,6 @@
![ngx_pagespeed](https://lh6.googleusercontent.com/-qufedJIJq7Y/UXEvVYxyYvI/AAAAAAAADo8/JHDFQhs91_c/s401/04_ngx_pagespeed.png)
[![Build Status](https://travis-ci.org/pagespeed/ngx_pagespeed.svg?branch=trunk-tracking)](https://travis-ci.org/pagespeed/ngx_pagespeed)
[![Build Status](https://travis-ci.org/pagespeed/ngx_pagespeed.svg?branch=master)](https://travis-ci.org/pagespeed/ngx_pagespeed)
ngx_pagespeed speeds up your site and reduces page load time by automatically
applying web performance best practices to pages and associated assets (CSS,
+27 -2
View File
@@ -15,9 +15,11 @@
# Environment Variables (Optional):
# MOD_PAGESPEED_DIR: absolute path to the mod_pagespeed/src directory
# PSOL_BINARY: absolute path to pagespeed_automatic.a
# PSOL_BUILDTYPE: Release or Debug
mod_pagespeed_dir="${MOD_PAGESPEED_DIR:-unset}"
position_aux="${POSITION_AUX:-unset}"
psol_buildtype="${PSOL_BUILDTYPE:-unset}"
if [ "$mod_pagespeed_dir" = "unset" ] ; then
mod_pagespeed_dir="$ngx_addon_dir/psol/include"
@@ -26,7 +28,8 @@ if [ "$mod_pagespeed_dir" = "unset" ] ; then
if [ ! -e "$mod_pagespeed_dir" ] ; then
echo "ngx_pagespeed: pagespeed optimization library not found:"
psol_binary_url="$(cat $ngx_addon_dir/PSOL_BINARY_URL)"
psol_binary_url="$($ngx_addon_dir/scripts/format_binary_url.sh \
$ngx_addon_dir/PSOL_BINARY_URL)"
if [[ "$psol_binary_url" != https://* ]]; then
echo "
This is a development branch of ngx_pagespeed, which means there is no
@@ -74,11 +77,17 @@ else
exit 1
fi
if [ "$psol_buildtype" = "unset" ] ; then
if [ "$NGX_DEBUG" = "YES" ]; then
buildtype=Debug
# If we're using a psol tarball that doesn't contain Debug/ (which is the case
# from 1.12 onward) then this will be overriden to buildtype=Release below.
else
buildtype=Release
fi
else
buildtype=$psol_buildtype
fi
# If the compiler is gcc, we want to use g++ to link, if at all possible,
# so that -static-libstdc++ works.
@@ -143,6 +152,22 @@ if [ "$psol_binary" = "unset" ] ; then
psol_binary="\
$mod_pagespeed_dir/pagespeed/automatic/pagespeed_automatic.a"
else
if ! [ -d "$ngx_addon_dir/psol/lib/$buildtype" ]; then
echo "
You have set --with-debug for building nginx, but precompiled Debug binaries for
PSOL, which ngx_pagespeed depends on, aren't available. If you're trying to
debug PSOL you need to build it from source. If you just want to run nginx with
debug-level logging you can use the Release binaries."
echo -n "
Use the available Release binaries?"
read -p " [Y/n] " yn
if [[ "$yn" == N* || "$yn" == n* ]]; then
echo "Cancelled."
exit 1
fi
buildtype=Release
fi
psol_library_dir="$ngx_addon_dir/psol/lib/$buildtype/$os_name/$arch_name"
psol_binary="$psol_library_dir/pagespeed_automatic.a"
fi
@@ -179,7 +204,7 @@ pagespeed_include="\
$mod_pagespeed_dir/url"
ngx_feature_path="$pagespeed_include"
pagespeed_libs="$psol_binary $pagespeed_libs -lrt -pthread -lm"
pagespeed_libs="$psol_binary $pagespeed_libs -lrt -pthread -lm -luuid"
ngx_feature_libs="$pagespeed_libs"
ngx_feature_test="
+333 -53
View File
@@ -1,11 +1,34 @@
#!/bin/bash
#
# Copyright 2016 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.
function usage() {
echo "
Usage: build_ngx_pagespeed.sh [options]
Installs ngx_pagespeed and its dependencies. Can optionally build and install
nginx as well.
nginx as well. Can be run either as:
bash <(curl -f -L -sS https://ngxpagespeed.com/install) [options]
Or:
git clone git@github.com:pagespeed/ngx_pagespeed.git
cd ngx_pagespeed/
git checkout <branch>
scripts/build_ngx_pagespeed.sh [options]
Options:
-v, --ngx-pagespeed-version <ngx_pagespeed version>
@@ -14,7 +37,11 @@ Options:
* latest-stable
* a version number, such as 1.11.33.4
If you don't specify a version, defaults to latest-stable.
If you don't specify a version, defaults to latest-stable unless --devel
is specified, in which case it defaults to master.
This option doesn't make sense if we're running within an existing
ngx_pagespeed checkout.
-n, --nginx-version <nginx version>
What version of nginx to build. If not set, this script only prepares the
@@ -36,6 +63,30 @@ Options:
non-deb non-rpm system, this won't work. In that case, install the
dependencies yourself and pass --no-deps-check.
-s, --psol-from-source
Build PSOL from source instead of downloading a pre-built binary module.
-l, --devel
Sets up a development environment in ngx_pagespeed/nginx, building with
testing-only dependencies. Includes --psol-from-source, conflicts with
--nginx-version. Uses a 'git clone' checkout for ngx_pagespeed and nginx
instead of downloading a tarball.
-t, --build-type
When building PSOL from source, what to tell it for BUILD_TYPE. Defaults
to 'Release' unless --devel is set in which case it defaults to 'Debug'.
-y, --assume-yes
Assume the answer to all prompts is 'yes, please continue'. Intended for
automated usage, such as buildbots.
-a, --additional-nginx-configure-arguments
When running ./configure for nginx, you may want to specify additional
arguments, such as --with-http_ssl_module. By default this script will
pause and prompt you for them, but this option lets you pass them in. For
example, you might do:
-a '--with-http_ssl_module --with-cc-opt=\"-I /usr/local/include\"'
-d, --dryrun
Don't make any changes to the system, just print what changes you
would have made.
@@ -44,10 +95,34 @@ Options:
Print this message and exit."
}
RED=31
GREEN=32
YELLOW=33
function begin_color() {
color="$1"
echo -e -n "\e[${color}m"
}
function end_color() {
echo -e -n "\e[0m"
}
function echo_color() {
color="$1"
shift
begin_color "$color"
echo "$@"
end_color
}
function error() {
local error_message="$@"
echo_color "$RED" -n "Error: " >&2
echo "$@" >&2
}
# Prints an error message and exits with an error code.
function fail() {
local error_message="$@"
echo "$@" >&2
error "$@"
# Normally I'd use $0 in "usage" here, but since most people will be running
# this via curl, that wouldn't actually give something useful.
@@ -56,6 +131,11 @@ function fail() {
exit 1
}
function status() {
echo_color "$GREEN" "$@"
}
# Intended to be called as:
# bash <(curl dl.google.com/.../build_ngx_pagespeed.sh) <args>
@@ -64,12 +144,19 @@ function fail() {
# The run function handles exit-status checking for system-changing commands.
# Additionally, this allows us to easily have a dryrun mode where we don't
# actually make any changes.
INITIAL_ENV=$(printenv | sort)
function run() {
if "$DRYRUN"; then
echo "would run $@"
echo_color "$YELLOW" -n "would run"
echo " $@"
env_differences=$(comm -13 <(echo "$INITIAL_ENV") <(printenv | sort))
if [ -n "$env_differences" ]; then
echo " with the following additional environment variables:"
echo "$env_differences" | sed 's/^/ /'
fi
else
if ! "$@"; then
echo "Failure running $@, exiting."
error "Failure running '$@', exiting."
exit 1
fi
fi
@@ -155,9 +242,9 @@ function install_dependencies() {
fi
done
if [ -n "$missing_dependencies" ]; then
echo "Detected that we're missing the following depencencies:"
status "Detected that we're missing the following depencencies:"
echo " $missing_dependencies"
echo "Installing them:"
status "Installing them:"
run sudo $install_pkg_cmd $missing_dependencies
fi
}
@@ -176,8 +263,13 @@ function gcc_too_old() {
}
function continue_or_exit() {
if "$ASSUME_YES"; then
return
fi
local prompt="$1"
read -p "$prompt [Y/n] " yn
echo_color "$YELLOW" -n "$prompt"
read -p " [Y/n] " yn
if [[ "$yn" == N* || "$yn" == n* ]]; then
echo "Cancelled."
exit 0
@@ -217,9 +309,10 @@ function build_ngx_pagespeed() {
fail "Your version of getopt is too old. Exiting with no changes made."
fi
opts=$(getopt -o v:n:mb:pdh \
opts=$(getopt -o v:n:mb:pslt:ya:dh \
--longoptions ngx-pagespeed-version:,nginx-version:,dynamic-module \
--longoptions buildir:,no-deps-check,dryrun,help \
--longoptions buildir:,no-deps-check,psol-from-source,devel,build-type: \
--longoptions assume-yes,additional-nginx-configure-arguments:,dryrun,help \
-n "$(basename "$0")" -- "$@")
if [ $? != 0 ]; then
usage
@@ -227,10 +320,14 @@ function build_ngx_pagespeed() {
fi
eval set -- "$opts"
NPS_VERSION="latest-stable"
NPS_VERSION="DEFAULT"
NGINX_VERSION=""
BUILDDIR="$HOME"
DO_DEPS_CHECK=true
PSOL_FROM_SOURCE=false
DEVEL=false
BUILD_TYPE=""
ASSUME_YES=false
DRYRUN=false
DYNAMIC_MODULE=false
while true; do
@@ -253,6 +350,23 @@ function build_ngx_pagespeed() {
-p | --no-deps-check) shift
DO_DEPS_CHECK=false
;;
-s | --psol-from-source) shift
PSOL_FROM_SOURCE=true
;;
-l | --devel) shift
DEVEL=true
;;
-t | --build-type) shift
BUILD_TYPE="$1"
shift
;;
-y | --assume-yes) shift
ASSUME_YES="true"
;;
-a | --additional-nginx-configure-arguments) shift
ADDITIONAL_NGINX_CONFIGURE_ARGUMENTS="$1"
shift
;;
-d | --dryrun) shift
DRYRUN="true"
;;
@@ -271,10 +385,58 @@ function build_ngx_pagespeed() {
esac
done
USE_GIT_CHECKOUT="$DEVEL"
ALREADY_CHECKED_OUT=false
if [ -e PSOL_BINARY_URL ]; then
status "Detected that we're running in an existing ngx_pagespeed checkout."
USE_GIT_CHECKOUT=true
ALREADY_CHECKED_OUT=true
fi
if "$ALREADY_CHECKED_OUT"; then
if [ "$NPS_VERSION" != "DEFAULT" ]; then
fail \
"The --ngx-pagespeed-version argument doesn't make sense when running within an existing checkout."
fi
elif [ "$NPS_VERSION" = "DEFAULT" ]; then
if "$DEVEL"; then
NPS_VERSION="master"
else
NPS_VERSION="latest-stable"
fi
fi
if [ ! -d "$BUILDDIR" ]; then
fail "Told to build in $BUILDDIR, but that directory doesn't exist."
fi
BUILD_NGINX=false
if [ -n "$NGINX_VERSION" ]; then
BUILD_NGINX=true
fi
if "$DEVEL"; then
PSOL_FROM_SOURCE=true
BUILD_NGINX=true
if [ -n "$NGINX_VERSION" ]; then
fail \
"The --devel argument conflicts with --nginx. In devel mode we use the version of nginx that's included as a submodule."
fi
if "$DYNAMIC_MODULE"; then
fail "Can't currently build a dynamic module in --devel mode."
fi
fi
if "$PSOL_FROM_SOURCE" && [ -z "$BUILD_TYPE" ]; then
if "$DEVEL"; then
BUILD_TYPE="Debug"
else
BUILD_TYPE="Release"
fi
elif [ -n "$BUILD_TYPE" ]; then
fail "Setting --build-type requires --psol-from-source or --devel."
fi
if [ "$NGINX_VERSION" = "latest" ]; then
# When this function fails it prints the debugging information needed first
# to stderr.
@@ -283,8 +445,15 @@ function build_ngx_pagespeed() {
if "$DYNAMIC_MODULE"; then
# Check that ngx_pagespeed and nginx are recent enough to support dynamic
# modules.
if version_older_than "$NPS_VERSION" "1.10.33.5"; then
# modules. Unfortunately NPS_VERSION might be a tag, in which case we don't
# know. If it's not a numeric version number, then assume it's recent
# enough and if it's not they'll get an ugly compilation error later.
# Luckily 1.10.33.5 was a while ago now.
#
# I'd like to use =~ here, but they changed syntax between v3 and v4 (quotes
# moved from mandatory to optional to prohibited).
if [[ "${NPS_VERSION#*[^0-9.]}" = "$NPS_VERSION" ]] &&
version_older_than "$NPS_VERSION" "1.10.33.5"; then
fail "
You're trying to build ngx_pagespeed $NPS_VERSION as a dynamic module, but
ngx_pagespeed didn't add support for dynamic modules until 1.10.33.5."
@@ -314,16 +483,16 @@ add support for dynamic modules in a way compatible with ngx_pagespeed until
# Now make sure our dependencies are installed.
if "$DO_DEPS_CHECK"; then
if [ -f /etc/debian_version ]; then
echo "Detected debian-based distro."
status "Detected debian-based distro."
install_dependencies "apt-get install" debian_is_installed \
"build-essential zlib1g-dev libpcre3 libpcre3-dev unzip"
build-essential zlib1g-dev libpcre3 libpcre3-dev unzip uuid-dev
if gcc_too_old; then
if [ ! -e /usr/lib/gcc-mozilla/bin/gcc ]; then
echo "Detected that gcc is older than 4.8. Installing gcc-mozilla"
echo "which installs gcc-4.8 into /usr/lib/gcc-mozilla/ and doesn't"
echo "affect your global gcc installation."
status "Detected that gcc is older than 4.8. Installing gcc-mozilla"
status "which installs gcc-4.8 into /usr/lib/gcc-mozilla/ and doesn't"
status "affect your global gcc installation."
run sudo apt-get install gcc-mozilla
fi
@@ -332,10 +501,10 @@ add support for dynamic modules in a way compatible with ngx_pagespeed until
fi
elif [ -f /etc/redhat-release ]; then
echo "Detected redhat-based distro."
status "Detected redhat-based distro."
install_dependencies "yum install" redhat_is_installed \
"gcc-c++ pcre-devel zlib-devel make unzip wget"
gcc-c++ pcre-devel zlib-devel make unzip wget libuuid-devel
if gcc_too_old; then
if [ ! -e /opt/rh/devtoolset-2/root/usr/bin/gcc ]; then
redhat_major_version=$(
@@ -350,9 +519,9 @@ Unexpected major version $redhat_major_version in /etc/redhat-release:
$(cat /etc/redhat-release) Expected 5 or 6."
fi
echo "Detected that gcc is older than 4.8. Scientific Linux provides"
echo "a gcc package that installs gcc-4.8 into /opt/ and doesn't"
echo "affect your global gcc installation."
status "Detected that gcc is older than 4.8. Scientific Linux"
status "provides a gcc package that installs gcc-4.8 into /opt/ and"
status "doesn't affect your global gcc installation."
slc_key="https://linux.web.cern.ch/linux/scientific6/docs/repository/"
slc_key+="cern/slc6X/i386/RPM-GPG-KEY-cern"
slc_key_out="$TEMPDIR/RPM-GPG-KEY-cern"
@@ -378,9 +547,9 @@ This doesn't appear to be a deb-based distro or an rpm-based one. Not going to
be able to install dependencies. Please install dependencies manually and rerun
with --no-deps-check."
fi
echo "Dependencies are all set."
status "Operating system dependencies are all set."
else
echo "Not checking whether dependencies are installed."
status "Not checking whether operating system dependencies are installed."
fi
function delete_if_already_exists() {
@@ -391,7 +560,6 @@ with --no-deps-check."
if [ ${#directory} -lt 8 ]; then
fail "
Not deleting $directory; name is suspiciously short. Something is wrong."
exit 1
fi
continue_or_exit "OK to delete $directory?"
@@ -399,28 +567,84 @@ Not deleting $directory; name is suspiciously short. Something is wrong."
fi
}
nps_baseurl="https://github.com/pagespeed/ngx_pagespeed/archive"
# In general, the zip github builds for tag foo unzips to ngx_pagespeed-foo,
# but it looks like they special case vVERSION tags to ngx_pagespeed-VERSION.
# but it looks like they special case vVERSION tags to ngx_pagespeed-VERSION
if [[ "$NPS_VERSION" =~ ^[0-9]*[.][0-9]*[.][0-9]*[.][0-9]*$ ]]; then
# We've been given a numeric version number. This has an associated tag in
# the form vVERSION-beta.
nps_url_fname="v${NPS_VERSION}-beta"
# We've been given a numeric version number. This has an associated tag
# in the form vVERSION-beta.
tag_name="v${NPS_VERSION}-beta"
nps_downloaded_fname="ngx_pagespeed-${NPS_VERSION}-beta"
else
# We've been given a tag name, like latest-beta. Download that directly.
nps_url_fname="$NPS_VERSION"
tag_name="$NPS_VERSION"
nps_downloaded_fname="ngx_pagespeed-${NPS_VERSION}"
fi
install_dir="this-only-makes-sense-in-devel-mode"
if "$USE_GIT_CHECKOUT"; then
# We're either doing a --devel build, or someone is running us from an
# existing git checkout.
nps_module_dir="$PWD"
install_dir="$nps_module_dir"
if "$ALREADY_CHECKED_OUT"; then
run cd "$nps_module_dir"
else
status "Checking out ngx_pagespeed..."
run git clone "git@github.com:pagespeed/ngx_pagespeed.git" \
"$nps_module_dir"
run cd "$nps_module_dir"
run git checkout "$tag_name"
fi
submodules_dir="$nps_module_dir/testing-dependencies"
if "$DEVEL"; then
status "Downloading dependencies..."
run git submodule update --init --recursive
if [[ "$CONTINUOUS_INTEGRATION" != true ]]; then
status "Switching submodules over to git protocol."
# This lets us push to github by public key.
for config in $(find .git/ -name config) ; do
run sed -i s~https://github.com/~git@github.com:~ $config ;
done
fi
fi
else
nps_baseurl="https://github.com/pagespeed/ngx_pagespeed/archive"
nps_downloaded="$TEMPDIR/$nps_downloaded_fname.zip"
run wget "$nps_baseurl/$nps_url_fname.zip" -O "$nps_downloaded"
status "Downloading ngx_pagespeed..."
run wget "$nps_baseurl/$tag_name.zip" -O "$nps_downloaded"
nps_module_dir="$BUILDDIR/$nps_downloaded_fname"
delete_if_already_exists "$nps_module_dir"
echo "Extracting ngx_pagespeed..."
status "Extracting ngx_pagespeed..."
run unzip -q "$nps_downloaded" -d "$BUILDDIR"
run cd "$nps_module_dir"
fi
MOD_PAGESPEED_DIR=""
PSOL_BINARY=""
if "$PSOL_FROM_SOURCE"; then
MOD_PAGESPEED_DIR="$PWD/testing-dependencies/mod_pagespeed"
git submodule update --init --recursive -- "$MOD_PAGESPEED_DIR"
run pushd "$MOD_PAGESPEED_DIR"
if "$DEVEL"; then
if [ ! -d "$HOME/apache2" ]; then
run install/build_development_apache.sh 2.2 prefork
fi
cd devel
run make apache_debug_psol
PSOL_BINARY="$MOD_PAGESPEED_DIR/out/$BUILD_TYPE/pagespeed_automatic.a"
else
if "$DO_DEPS_CHECK"; then
skip_deps_arg=""
else
skip_deps_arg="--skip_deps"
fi
run install/build_psol.sh --skip_tests --skip_packaging "$skip_deps_arg"
PSOL_BINARY="$MOD_PAGESPEED_DIR/pagespeed/automatic/pagespeed_automatic.a"
fi
run popd
else
# Now we need to figure out what precompiled version of PSOL to build
# ngx_pagespeed against.
if "$DRYRUN"; then
@@ -428,24 +652,27 @@ Not deleting $directory; name is suspiciously short. Something is wrong."
elif [ -e PSOL_BINARY_URL ]; then
# Releases after 1.11.33.4 there is a PSOL_BINARY_URL file that tells us
# where to look.
psol_url="$(cat PSOL_BINARY_URL)"
psol_url="$(scripts/format_binary_url.sh PSOL_BINARY_URL)"
if [[ "$psol_url" != https://* ]]; then
fail "Got bad psol binary location information: $psol_url"
fi
else
# For past releases we have to grep it from the config file. The url has
# always looked like this, and the config file has contained it since before
# we started tagging our ngx_pagespeed releases.
psol_url="$(
grep -o "https://dl.google.com/dl/page-speed/psol/[0-9.]*.tar.gz" config)"
# always looked like this, and the config file has contained it since
# before we started tagging our ngx_pagespeed releases.
psol_url="$(grep -o \
"https://dl.google.com/dl/page-speed/psol/[0-9.]*.tar.gz" config)"
if [ -z "$psol_url" ]; then
fail "Couldn't find PSOL url in $PWD/config"
fi
fi
status "Downloading PSOL binary..."
run wget "$psol_url"
echo "Extracting PSOL..."
status "Extracting PSOL..."
run tar -xzf $(basename "$psol_url") # extracts to psol/
fi
if "$DYNAMIC_MODULE"; then
add_module="--add-dynamic-module=$nps_module_dir"
@@ -454,17 +681,37 @@ Not deleting $directory; name is suspiciously short. Something is wrong."
fi
configure_args=("$add_module" "${extra_flags[@]}")
if "$DEVEL"; then
configure_args=("${configure_args[@]}"
"--prefix=$install_dir/nginx"
"--add-module=$submodules_dir/ngx_cache_purge"
"--add-module=$submodules_dir/ngx_devel_kit"
"--add-module=$submodules_dir/set-misc-nginx-module"
"--add-module=$submodules_dir/headers-more-nginx-module"
"--with-ipv6"
"--with-http_v2_module")
if [ "$BUILD_TYPE" = "Debug" ]; then
configure_args=("${configure_args[@]}" "--with-debug")
fi
fi
echo
if [ -z "$NGINX_VERSION" ]; then
# They didn't specify an nginx version, so we're just preparing the
# module for them to install.
echo "ngx_pagespeed is ready to be built against nginx."
echo "When running ./configure pass in:"
if ! "$BUILD_NGINX"; then
# Just prepare the module for them to install.
status "ngx_pagespeed is ready to be built against nginx."
echo "When running ./configure:"
if "$PSOL_FROM_SOURCE"; then
echo " Set the following environment variables:"
echo " MOD_PAGESPEED_DIR=$MOD_PAGESPEED_DIR"
echo " PSOL_BINARY=$PSOL_BINARY"
fi
echo " Give ./configure the following arguments:"
echo " $(quote_arguments "${configure_args[@]}")"
echo
if [ ${#extra_flags[@]} -eq 0 ]; then
echo "If this is for integration with an already-built nginx, make sure"
echo "to include any other arguments you originally passed to ./configure"
echo "You can see these with 'nginx -V'."
echo "to include any other arguments you originally passed to"
echo "./configure. You can see these with 'nginx -V'."
else
echo "Note: because we need to set $(quote_arguments "${extra_flags[@]}")"
echo "on this platform, if you want to integrate ngx_pagespeed with an"
@@ -472,36 +719,68 @@ Not deleting $directory; name is suspiciously short. Something is wrong."
echo "those flags set."
fi
else
# Download and build nginx.
if "$DEVEL"; then
# Use the nginx we loaded as a submodule
nginx_dir="$submodules_dir/nginx"
configure_location="auto"
else
# Download and build the specified nginx version.
nginx_leaf="nginx-${NGINX_VERSION}.tar.gz"
nginx_fname="$TEMPDIR/$nginx_leaf"
status "Downloading nginx..."
run wget "http://nginx.org/download/$nginx_leaf" -O "$nginx_fname"
nginx_dir="$BUILDDIR/nginx-${NGINX_VERSION}/"
delete_if_already_exists "$nginx_dir"
echo "Extracting nginx..."
status "Extracting nginx..."
run tar -xzf "$nginx_fname" --directory "$BUILDDIR"
"$DRYRUN" || cd "$nginx_dir"
configure_location="."
fi
run cd "$nginx_dir"
configure=("./configure" "${configure_args[@]}")
configure=("$configure_location/configure" "${configure_args[@]}")
additional_configure_args=""
if [ -z "${ADDITIONAL_NGINX_CONFIGURE_ARGUMENTS+x}" ]; then
if ! "$ASSUME_YES"; then
echo "About to build nginx. Do you have any additional ./configure"
echo "arguments you would like to set? For example, if you would like"
echo "to build nginx with https support give --with-http_ssl_module"
echo "If you don't have any, just press enter."
read -p "> " additional_configure_args
fi
else
additional_configure_args="$ADDITIONAL_NGINX_CONFIGURE_ARGUMENTS"
fi
if [ -n "$additional_configure_args" ]; then
# Split additional_configure_args respecting any internal quotation.
# Otherwise things like --with-cc-opt='-foo -bar' won't work.
eval additional_configure_args=("$additional_configure_args")
configure=("${configure[@]}" "${additional_configure_args[@]}")
fi
echo "About to configure nginx with:"
echo " $(quote_arguments "${configure[@]}")"
continue_or_exit "Does this look right?"
MOD_PAGESPEED_DIR="$MOD_PAGESPEED_DIR" \
PSOL_BINARY="$PSOL_BINARY" \
run "${configure[@]}"
if ! "$DEVEL"; then
continue_or_exit "Build nginx?"
fi
run make
if "$DEVEL"; then
run make install
status "Nginx installed with ngx_pagespeed, and set up for development."
echo "To run tests:"
echo " cd $nps_module_dir"
echo " test/run_tests.sh"
echo
echo "To rebuild after changes:"
echo " scripts/rebuild.sh"
else
continue_or_exit "Install nginx?"
run sudo make install
@@ -524,8 +803,9 @@ Not deleting $directory; name is suspiciously short. Something is wrong."
echo "You'll also need to configure ngx_pagespeed if you haven't yet:"
echo " https://developers.google.com/speed/pagespeed/module/configuration"
fi
fi
if "$DRYRUN"; then
echo "[this was a dry run; your system is unchanged]"
echo_color "$YELLOW" "[this was a dry run; your system is unchanged]"
fi
}
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
#
# Copyright 2016 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.
set -e
set -u
if [ $# -ne 1 ]; then
echo "Usage: $(basename $0) <url_file>" >&2
exit 1
fi
url_file=$1
if [ ! -e "$url_file" ]; then
echo "Url file '$url_file' missing!" >&2
fi
# The size names must match install/build_psol.sh in mod_pagespeed
if [ "$(uname -m)" = x86_64 ]; then
bit_size_name=x64
else
bit_size_name=ia32
fi
sed -e 's/$BIT_SIZE_NAME\b/'$bit_size_name'/g' $url_file
+14
View File
@@ -1,5 +1,19 @@
#!/bin/bash
#
# 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.
#
# Converts pagespeed_libraries.conf from Apache-format to Nginx-format,
# supporting the canonicalize_javascript_libraries filter.
# Inspired by https://github.com/pagespeed/ngx_pagespeed/issues/532
-94
View File
@@ -1,94 +0,0 @@
#!/bin/bash
#
# Copyright 2012 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: jefftk@google.com (Jeff Kaufman)
#
# Usage:
# scripts/prepare_psol.sh /path/to/mod_pagespeed/src
#
# Creates a directory psol/ and copies headers and a few source files from a
# depot_tools (glient) checkout into psol/include. Along with creating
# binaries, this is a step in preparing psol.tar.gz for distribution.
#
set -u # check for undefined variables
set -e # exit on failed commands
if [ "$(basename "$PWD")" != "ngx_pagespeed" ] ; then
echo "$(basename $0) must be invoked from the ngx_pagespeed directory"
exit 1
fi
if [ $# -ne 1 ] ; then
echo "Usage: $(basename $0) /path/to/mod_pagespeed/src"
exit 1
fi
MOD_PAGESPEED_SRC="$1"
if [ "$(basename "$(dirname "$MOD_PAGESPEED_SRC")")/$( \
basename "$MOD_PAGESPEED_SRC")" != "mod_pagespeed/src" ] ; then
echo "Usage: $(basename $0) /path/to/mod_pagespeed/src"
exit 1
fi
if [ -e psol ] ; then
echo "A psol/ directory already exists. Move it somewhere else and rerun."
exit 1
fi
mkdir psol/
# Copy over the .h files, plus a few selected .cc and .c files.
rsync -arvz "$MOD_PAGESPEED_SRC/" "psol/include/" --prune-empty-dirs \
--exclude=".svn" \
--exclude=".git" \
--include='*.h' \
--include='*/' \
--include="apr_thread_compatible_pool.cc" \
--include="serf_url_async_fetcher.cc" \
--include="apr_mem_cache.cc" \
--include="key_value_codec.cc" \
--include="apr_memcache2.c" \
--include="loopback_route_fetcher.cc" \
--include="add_headers_fetcher.cc" \
--include="console_css_out.cc" \
--include="console_out.cc" \
--include="dense_hash_map" \
--include="dense_hash_set" \
--include="sparse_hash_map" \
--include="sparse_hash_set" \
--include="sparsetable" \
--include="mod_pagespeed_console_out.cc" \
--include="mod_pagespeed_console_css_out.cc" \
--include="mod_pagespeed_console_html_out.cc" \
--exclude='*'
mkdir -p psol/lib/Debug/linux/ia32
mkdir -p psol/lib/Debug/linux/x64
mkdir -p psol/lib/Release/linux/ia32
mkdir -p psol/lib/Release/linux/x64
# Log that we did this.
SVN_REVISION="$(svn info $MOD_PAGESPEED_SRC | grep Revision | awk '{print $2}')"
SVN_TAG="$(svn info $MOD_PAGESPEED_SRC | grep URL | awk -F/ '{print $(NF-1)}')"
DATE="$(date +%F)"
echo "${DATE}: Copied from mod_pagespeed ${SVN_TAG}@r${SVN_REVISION} ($USER)" \
>> psol/include_history.txt
echo
echo "Output is in psol/include. Now put binaries in psol/lib following"
echo "https://github.com/pagespeed/ngx_pagespeed/wiki/Building-Release-Binaries"
echo "and then you can distribute PSOL."
+35
View File
@@ -0,0 +1,35 @@
#!/bin/bash
#
# Copyright 2016 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.
# Usage: scripts/rebuild.sh
#
# After building with "scripts/build_ngx_pagespeed.sh --devel", if you make
# changes to ngx_pagespeed you'll need to rebuild it. The underlying commands
# aren't complicated, but it's faster to work if it's automated.
set -e # exit script if any command returns an error
set -u # exit the script if any variable is uninitialized
this_dir="$(dirname $0)"
cd "$this_dir/.."
nps_dir="$PWD"
cd "$nps_dir/testing-dependencies/mod_pagespeed/devel"
make apache_debug_psol
cd "$nps_dir/testing-dependencies/nginx/"
make
make install
+8
View File
@@ -52,6 +52,14 @@ bool NgxEventConnection::Init(ngx_cycle_t* cycle) {
} else {
pipe_read_fd_ = file_descriptors[0];
pipe_write_fd_ = file_descriptors[1];
// Attempt to bump the pipe capacity, because running out of buffer space
// can potentially lead up to writes spinning on EAGAIN.
// See https://github.com/pagespeed/ngx_pagespeed/issues/1380
// TODO(oschaaf): Consider implementing a queueing mechanism for retrying
// failed writes.
#ifdef F_SETPIPE_SZ
fcntl(pipe_write_fd_, F_SETPIPE_SZ, 200*1024 /* minimal amount of bytes */);
#endif
return true;
}
close(file_descriptors[0]);
+46 -21
View File
@@ -84,6 +84,7 @@ extern ngx_module_t ngx_pagespeed;
// Needed for SystemRewriteDriverFactory to use shared memory.
#define PAGESPEED_SUPPORT_POSIX_SHARED_MEM
#define NGINX_1_13_4 1013004
net_instaweb::NgxRewriteDriverFactory* active_driver_factory = NULL;
@@ -239,6 +240,9 @@ ngx_http_output_body_filter_pt ngx_http_next_body_filter;
ngx_int_t ps_base_fetch_filter(ngx_http_request_t* r, ngx_chain_t* in) {
ps_request_ctx_t* ctx = ps_get_request_context(r);
if (r->header_only) {
return NGX_OK;
}
if (ctx == NULL || ctx->base_fetch == NULL) {
return ngx_http_next_body_filter(r, in);
}
@@ -749,6 +753,11 @@ ngx_command_t ps_commands[] = {
ngx_null_command
};
bool ps_disabled(ps_srv_conf_t* cfg_s) {
return cfg_s->server_context == NULL ||
cfg_s->server_context->config()->unplugged();
}
void ps_ignore_sigpipe() {
struct sigaction act;
ngx_memzero(&act, sizeof(act));
@@ -881,8 +890,7 @@ char* ps_configure(ngx_conf_t* cf,
ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
ngx_http_cycle_get_module_main_conf(cf->cycle, ngx_pagespeed));
if (*options == NULL) {
*options = new NgxRewriteOptions(
cfg_m->driver_factory->thread_system());
*options = new NgxRewriteOptions(cfg_m->driver_factory->thread_system());
}
ProcessScriptVariablesMode script_mode =
@@ -1148,13 +1156,17 @@ char* ps_merge_srv_conf(ngx_conf_t* cf, void* parent, void* child) {
delete cfg_s->options;
cfg_s->options = NULL;
if (cfg_s->server_context->global_options()->enabled()) {
if (!cfg_s->server_context->global_options()->unplugged()) {
// Validate FileCachePath
GoogleMessageHandler handler;
const char* file_cache_path =
cfg_s->server_context->config()->file_cache_path().c_str();
if (file_cache_path[0] == '\0') {
if (!cfg_s->server_context->global_options()->standby()) {
return const_cast<char*>("FileCachePath must be set, even for standby");
} else {
return const_cast<char*>("FileCachePath must be set");
}
} else if (!cfg_m->driver_factory->file_system()->IsDir(
file_cache_path, &handler).is_true()) {
return const_cast<char*>(
@@ -1191,7 +1203,7 @@ char* ps_merge_loc_conf(ngx_conf_t* cf, void* parent, void* child) {
ps_srv_conf_t* cfg_s = static_cast<ps_srv_conf_t*>(
ngx_http_conf_get_module_srv_conf(cf, ngx_pagespeed));
if (cfg_s->server_context == NULL) {
if (ps_disabled(cfg_s)) {
// Pagespeed options cannot be defined only in location blocks. There must
// be at least a single "pagespeed off" in the main block or a server
// block.
@@ -1698,7 +1710,7 @@ void ps_release_request_context(void* data) {
RequestRouting::Response ps_route_request(ngx_http_request_t* r) {
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
if (!cfg_s->server_context->global_options()->enabled()) {
if (ps_disabled(cfg_s)) {
// Not enabled for this server block.
return RequestRouting::kPagespeedDisabled;
}
@@ -1840,11 +1852,6 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r,
options = cfg_s->server_context->global_options();
}
if (!options->enabled()) {
// Disabled via query params or request headers.
return NGX_DECLINED;
}
request_context->set_options(options->ComputeHttpOptions());
// ps_determine_options modified url, removing any ModPagespeedFoo=Bar query
@@ -1871,6 +1878,14 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r,
response_category == RequestRouting::kGlobalAdmin ||
response_category == RequestRouting::kCachePurge;
// Normally if we're disabled we won't handle any requests, but if we're in
// standby mode we do want to handle requests for .pagespeed. resources.
if (options->unplugged() ||
(!options->enabled() && !pagespeed_resource)) {
// Disabled via query params or request headers.
return NGX_DECLINED;
}
if (!html_rewrite) {
// create request ctx
CHECK(ctx == NULL);
@@ -2050,8 +2065,8 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r,
if (options->in_place_rewriting_enabled() &&
options->enabled() &&
options->IsAllowed(url.Spec())) {
ps_create_base_fetch(url.Spec(), ctx, request_context, request_headers.release(),
kIproLookup, options);
ps_create_base_fetch(url.Spec(), ctx, request_context,
request_headers.release(), kIproLookup, options);
// Do not store driver in request_context, it's not safe.
RewriteDriver* driver;
@@ -2277,8 +2292,7 @@ ngx_http_output_body_filter_pt ngx_http_next_body_filter;
// nginx so it can send them out to the browser.
ngx_int_t ps_html_rewrite_header_filter(ngx_http_request_t* r) {
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
if (cfg_s->server_context == NULL) {
// Pagespeed is on for some server block but not this one.
if (ps_disabled(cfg_s)) {
return ngx_http_next_header_filter(r);
}
@@ -2362,8 +2376,7 @@ ngx_int_t ps_html_rewrite_header_filter(ngx_http_request_t* r) {
ngx_int_t ps_html_rewrite_body_filter(ngx_http_request_t* r, ngx_chain_t* in) {
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
if (cfg_s->server_context == NULL) {
// Pagespeed is on for some server block but not this one.
if (ps_disabled(cfg_s)) {
return ngx_http_next_body_filter(r, in);
}
@@ -2691,8 +2704,7 @@ ngx_int_t ps_simple_handler(ngx_http_request_t* r,
}
}
send_out_headers_and_body(r, response_headers, output);
return NGX_OK;
return send_out_headers_and_body(r, response_headers, output);
}
void ps_beacon_handler_helper(ngx_http_request_t* r,
@@ -2887,8 +2899,8 @@ ngx_int_t ps_beacon_handler(ngx_http_request_t* r) {
// supply it to the user.
ngx_int_t ps_content_handler(ngx_http_request_t* r) {
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
if (cfg_s->server_context == NULL) {
// Pagespeed is on for some server block but not this one.
if (ps_disabled(cfg_s)) {
// Pagespeed is not on for this server block.
return NGX_DECLINED;
}
@@ -3007,13 +3019,17 @@ ngx_int_t ps_preaccess_handler(ngx_http_request_t* r) {
ph = cmcf->phase_engine.handlers;
i = r->phase_handler;
// move handlers before try_files && content phase
// As of nginx 1.13.4 we will be right before the try_files module
#if (nginx_version < NGINX_1_13_4)
while (ph[i + 1].checker != ngx_http_core_try_files_phase &&
ph[i + 1].checker != ngx_http_core_content_phase) {
ph[i] = ph[i + 1];
ph[i].next--;
i++;
}
#endif
// insert ps phase handler
ph[i].checker = ps_phase_handler;
@@ -3069,8 +3085,17 @@ ngx_int_t ps_init(ngx_conf_t* cf) {
ngx_http_core_main_conf_t* cmcf = static_cast<ngx_http_core_main_conf_t*>(
ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module));
int phase = NGX_HTTP_PREACCESS_PHASE;
// As of nginx 1.13.4, try_files has changed.
// https://github.com/nginx/nginx/commit/129b06dc5dfab7b4513a4f274b3778cd9b8a6a22
#if (nginx_version >= NGINX_1_13_4)
phase = NGX_HTTP_PRECONTENT_PHASE;
#endif
ngx_http_handler_pt* h = static_cast<ngx_http_handler_pt*>(
ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers));
ngx_array_push(&cmcf->phases[phase].handlers));
if (h == NULL) {
return NGX_ERROR;
}
+10 -7
View File
@@ -192,15 +192,18 @@ RewriteOptions::OptionScope NgxRewriteOptions::GetOptionScope(
RewriteOptions::OptionSettingResult NgxRewriteOptions::ParseAndSetOptions0(
StringPiece directive, GoogleString* msg, MessageHandler* handler) {
if (IsDirective(directive, "on")) {
set_enabled(RewriteOptions::kEnabledOn);
} else if (IsDirective(directive, "off")) {
set_enabled(RewriteOptions::kEnabledOff);
} else if (IsDirective(directive, "unplugged")) {
set_enabled(RewriteOptions::kEnabledUnplugged);
} else {
EnabledEnum enabled;
if (!ParseFromString(directive, &enabled)) {
return RewriteOptions::kOptionNameUnknown;
}
if (enabled == RewriteOptions::kEnabledOff) {
// In ngx_pagespeed, for historical reasons, we treat "off" as "unplugged".
// Also, "off" is deprecated and people should be using "standby" or
// "unplugged" now depending on which sense they want. See comment on
// RewriteOptions::EnabledEnum.
enabled = RewriteOptions::kEnabledUnplugged;
}
set_enabled(enabled);
return RewriteOptions::kOptionOk;
}
+14 -3
View File
@@ -49,7 +49,11 @@ rm -rf "$TEST_TMP"
mkdir -p "$TEST_TMP"
echo TEST_TMP=$TEST_TMP
APACHE_DOC_SRC="$MOD_PAGESPEED_DIR/src/install/"
if [ -d "$MOD_PAGESPEED_DIR/src" ]; then
MOD_PAGESPEED_DIR+="/src"
fi
APACHE_DOC_SRC="$MOD_PAGESPEED_DIR/install/"
SERVER_ROOT="$TEST_TMP/root"
echo SERVER_ROOT=$SERVER_ROOT
rm -rf "$SERVER_ROOT"
@@ -311,7 +315,7 @@ SERVER_NAME=nginx
RUN_CONTROLLER_TEST=${RUN_CONTROLLER_TEST:-off}
# run generic system tests
PAGESPEED_DIR="$MOD_PAGESPEED_DIR/src/pagespeed"
PAGESPEED_DIR="$MOD_PAGESPEED_DIR/pagespeed"
SYSTEM_TEST_FILE="$PAGESPEED_DIR/system/system_test.sh"
REMOTE_CONFIG_TEST_FILE="$PAGESPEED_DIR/system/remote_config_test.sh"
@@ -365,6 +369,13 @@ fi
# wants different ones than we want, so we need to reset our positional args.
set -- "$PRIMARY_HOSTNAME"
source $SYSTEM_TEST_FILE
# If we were only asked to run a single test, it ran in SYSTEM_TEST_FILE, so
# we're done now and should exit.
if [ -n ${TEST_TO_RUN+x} ]; then
check_failures_and_exit
fi
source $REMOTE_CONFIG_TEST_FILE
# nginx-specific system tests
@@ -1420,7 +1431,7 @@ OUT=$(cat "$ERROR_LOG" \
| grep -v "\\[error\\].*forbidden.example.com*" \
| grep -v "\\[error\\].*custom-paths.example.com*" \
| grep -v "\\[error\\].*bogus_format*" \
| grep -v "\\[error\\].*src/install/foo*" \
| grep -v "\\[error\\].*/install/foo*" \
| grep -v "\\[error\\].*recv() failed*" \
| grep -v "\\[error\\].*send() failed*" \
| grep -v "\\[error\\].*Invalid url requested: js_defer.js.*" \
+65
View File
@@ -88,6 +88,16 @@ http {
# Expanded to CentralControllerPort directive when RUN_CONTROLLER_TEST=on
@@CONTROLLER@@
server {
# This is the default vhost for @@SECONDARY_PORT@@
# Your request will land here when you pass in an unknown host.
listen @@SECONDARY_PORT@@;
listen [::]:@@SECONDARY_PORT@@;
server_name default.example.com;
pagespeed FileCachePath "@@FILE_CACHE@@";
pagespeed RewriteLevel CoreFilters;
}
server {
# Sets up a logical home-page server on
# max-cacheable-content-length.example.com. This server is only used to
@@ -132,6 +142,42 @@ http {
"@@SERVER_ROOT@@/mod_pagespeed_example/styles/";
}
server {
listen @@SECONDARY_PORT@@;
listen [::]:@@SECONDARY_PORT@@;
server_name pagespeed-off.example.com;
pagespeed FileCachePath "@@FILE_CACHE@@";
pagespeed off;
pagespeed EnableFilters collapse_whitespace;
}
server {
listen @@SECONDARY_PORT@@;
listen [::]:@@SECONDARY_PORT@@;
server_name pagespeed-on.example.com;
pagespeed FileCachePath "@@FILE_CACHE@@";
pagespeed on;
pagespeed EnableFilters collapse_whitespace;
}
server {
listen @@SECONDARY_PORT@@;
listen [::]:@@SECONDARY_PORT@@;
server_name pagespeed-standby.example.com;
pagespeed FileCachePath "@@FILE_CACHE@@";
pagespeed standby;
pagespeed EnableFilters collapse_whitespace;
}
server {
listen @@SECONDARY_PORT@@;
listen [::]:@@SECONDARY_PORT@@;
server_name pagespeed-unplugged.example.com;
pagespeed FileCachePath "@@FILE_CACHE@@";
pagespeed unplugged;
pagespeed EnableFilters collapse_whitespace;
}
pagespeed UseNativeFetcher "@@NATIVE_FETCHER@@";
@@RESOLVER@@
@@ -1749,6 +1795,25 @@ http {
pagespeed DisableFilters add_instrumentation;
pagespeed CriticalImagesBeaconEnabled false;
}
server {
pagespeed on;
listen @@SECONDARY_PORT@@;
listen [::]:@@SECONDARY_PORT@@;
server_name image-rewrite-with-flush.example.com;
pagespeed FileCachePath "@@FILE_CACHE@@";
pagespeed RewriteLevel PassThrough;
pagespeed UrlValuedAttribute li data-thumb image;
pagespeed EnableFilters core;
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME $request_filename;
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_pass 127.0.0.1:9000;
fastcgi_buffering off;
}
}
server {
listen @@PRIMARY_PORT@@;
listen [::]:@@PRIMARY_PORT@@;
+17 -5
View File
@@ -23,8 +23,15 @@
# Exits with status 2 if command line args are wrong.
#
# Usage:
# ./run_tests.sh
# Or:
# ./run_tests.sh /path/to/mod_pagespeed /path/to/nginx/binary
#
# If you built ngx_pagespeed with "scripts/build_ngx_pagespeed.sh --devel" then
# you don't need to pass any arguments to run_tests.sh. Otherwise, you'll need
# to tell it where to find a mod_pagespeed checkout (for example html files etc)
# and the nginx binary to test.
#
# By default the test script uses several ports. If you have a port conflict
# and need to override one you can do that by setting the relevant environment
# variable. For example:
@@ -45,23 +52,28 @@ RUN_TESTS=${RUN_TESTS:-true}
# true.
USE_VALGRIND=${USE_VALGRIND:-false}
if [ "$#" -ne 2 ] ; then
echo "Usage: $0 mod_pagespeed_dir nginx_executable"
exit 2
fi
if [ "$#" -eq 0 ]; then
MOD_PAGESPEED_DIR="testing-dependencies/mod_pagespeed/"
NGINX_EXECUTABLE="nginx/sbin/nginx"
elif [ "$#" -eq 2 ]; then
MOD_PAGESPEED_DIR="$1"
NGINX_EXECUTABLE="$2"
else
echo "Usage: $0 [mod_pagespeed_dir nginx_executable]"
exit 2
fi
: ${PRIMARY_PORT:=8050}
: ${SECONDARY_PORT:=8051}
: ${CONTROLLER_PORT:=8053}
: ${RCPORT:=9991}
: ${PAGESPEED_TEST_HOST:=selfsigned.modpagespeed.com}
: ${PHP_PORT:=9000}
this_dir="$( cd $(dirname "$0") && pwd)"
function run_test_checking_failure() {
"$MOD_PAGESPEED_DIR/install/start_php.sh" "$PHP_PORT"
USE_VALGRIND="$USE_VALGRIND" \
PRIMARY_PORT="$PRIMARY_PORT" \
SECONDARY_PORT="$SECONDARY_PORT" \