Tag Archives: nginx

Compiling google’s mod_pagespeed for nginx

This post is intended mainly to Zyxel NSA310 users.

Prerequisites
See first https://adrhc.go.ro/blog/common-commands-when-building/ for building environment, x.sh script and other things not defined here.
Before starting do declare the environment variables specified to the link above.

Environment & other preparations
NEW_BUILD_NAME=ngx_pagespeed
NEW_BUILD_VER=20150317
NEW_BUILD_NAME_AND_VER=$NEW_BUILD_NAME-$NEW_BUILD_VER
ls -l /tmp/$NEW_BUILD_NAME-*
ls -l ~/ffp_0.7_armv5/packages/$NEW_BUILD_NAME-*
NEW_BUILD_NR=0

wget -O ngx_pagespeed-$NEW_BUILD_VER.zip https://github.com/pagespeed/ngx_pagespeed/archive/master.zip
unzip ngx_pagespeed-$NEW_BUILD_VER.zip
mv ngx_pagespeed-master/ ngx_pagespeed-$NEW_BUILD_VER

Build procedure
Read then do first https://adrhc.go.ro/blog/install-configure-googles-mod_pagespeed-for-apache/
cd ~/compile/mod_pagespeed/src/net/instaweb/automatic
~/x.sh ffpg1
make BUILDTYPE=Release AR.host="$PWD/../../../build/wrappers/ar.sh" AR.target="$PWD/../../../build/wrappers/ar.sh" all

Other considerations
See also https://github.com/pagespeed/ngx_pagespeed/wiki/Building-PSOL-From-Source

gitweb on nginx

nginx configuration

# Let Nginx handle static files # location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx)) { location ~ ^/[^/]*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx)) { auth_basic "strong authentication"; auth_basic_user_file /********/apps/etc/basic.auth.strong.passwords.txt; root /********/GITRepoUbuntu/; } # Pass Git Smart HTTP requests to git-http-backend. Require Auth for everything. # see man git-http-backend for Apache configuration #location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { location ~ ^/[^/]*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { auth_basic "strong authentication"; auth_basic_user_file /********/apps/etc/basic.auth.strong.passwords.txt; client_max_body_size 0; fastcgi_read_timeout 300; fastcgi_buffers 4 64K; include fastcgi_params; fastcgi_pass unix:/var/run/fastcgi.sock; fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; fastcgi_param GIT_PROJECT_ROOT /********/GITRepoUbuntu; fastcgi_param PATH_INFO $uri; fastcgi_param REMOTE_USER $remote_user; ### Uncomment below to export ALL repositories in GIT_PROJECT_ROOT path. fastcgi_param GIT_HTTP_EXPORT_ALL ""; } location /git/ { auth_basic "strong authentication"; auth_basic_user_file /********/apps/etc/basic.auth.strong.passwords.txt; try_files $uri @gitweb; } location @gitweb { fastcgi_pass unix:/var/run/fastcgi.sock; fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/gitweb.cgi; fastcgi_param PATH_INFO $uri; fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; include fastcgi_params; } # sudo systemctl status nginx fcgiwrap.service fcgiwrap.socket # sudo systemctl enable nginx fcgiwrap.service fcgiwrap.socket # sudo systemctl stop nginx fcgiwrap.service fcgiwrap.socket # sudo systemctl start fcgiwrap.socket fcgiwrap.service nginx

/etc/gitweb.conf

#see man gitweb # path to git projects (.git) $projectroot = "/********/GITRepoUbuntu/"; # directory to use for temp files # $git_temp = "/tmp"; # html text to include at home page # $home_text = "indextext.html"; # file with project list; by default, simply scan the projectroot dir. # $projects_list = "/home/git/projects.list"; @stylesheets = ("gitweb.css"); $javascript = "gitweb.js"; $favicon = "git-favicon.png"; $logo = "git-logo.png"; # git-diff-tree(1) options to use for generated patches @diff_opts = ('-C', '-C'); # enable nicer uris # $feature{pathinfo}{default} = [1]; $site_name = "adrhc's projects"; $home_link = "https://adrhc.go.ro/git/"; $home_link_str = "adrhc's projects"; $mimetypes_file = "/********/apps/etc/nginx/mime.types"; $base_url = "https://adrhc.go.ro/git/"; @git_base_url_list = qw(https://adrhc.go.ro); @extra_breadcrumbs = ( [ "adrhc's blog" => "https://adrhc.go.ro/" ] );

/etc/systemd/system/fcgiwrap.socket

[Unit] Description=fcgiwrap Socket [Socket] SocketMode=0660 SocketUser**** SocketGroup********* ListenStream=/var/run/fastcgi.sock [Install] WantedBy=sockets.target

/etc/systemd/system/fcgiwrap.service

[Unit] Description=Simple CGI Server After=nss-user-lookup.target [Service] # https://apuntesderootblog.wordpress.com/2015/06/01/how-to-run-gitweb-and-git-http-backend-with-nginx-in-fedora/ # sudo apt-get install fcgiwrap # systemctl daemon-reload # sudo systemctl enable fcgiwrap.socket fcgiwrap.service ExecStartPre=/bin/mkdir -p /var/cache/cgit ExecStartPre=/bin/chown ************ /var/cache/cgit #ExecStartPre=/bin/rm -rf /var/cache/cgit/* ExecStart=/usr/sbin/fcgiwrap User**** Group********* [Install] Also=fcgiwrap.socket

example bare repository config

cat /********/GITRepoUbuntu/test/git/config [core] repositoryformatversion = 0 filemode = false bare = true sharedrepository = 1 [receive] denyNonFastforwards = true [alias] st = status gr = log --full-history --all --graph --color --date-order --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s" ci = commit cim = commit -m ck = checkout ckm = checkout master ckd = checkout dev rs = reset mgnf = merge --no-ff mg = merge pom = push origin master pod = push origin development gom = pull origin master god = pull origin development [gitg] mainline = refs/heads/master # ERROR git clone https://adrhc.go.ro/exifweb.git edit some files then commit ... git push origin master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 303 bytes | 0 bytes/s, done. Total 3 (delta 2), reused 0 (delta 0) remote: error: unable to create temporary file: Operation not permitted remote: fatal: failed to write object error: unpack failed: unpack-objects abnormal exit To https://adrhc.go.ro/exifweb.git ! [remote rejected] master -> master (unpacker error) error: failed to push some refs to 'https://adrhc.go.ro/exifweb.git' # SOLUTION Make sure the user and group (and SocketMode) set for fcgiwrap OS service are appropriate for the git repository (when using http/https push).

Compiling nginx 1.9.2

#See https://adrhc.go.ro/wordpress/common-commands-when-building/ for building environment, x.sh script and other things not defined here.
#Before starting do declare the environment variables specified to the link above.

NEW_BUILD_NAME=nginx
NEW_BUILD_VER=1.9.1
NEW_BUILD_NAME_AND_VER=$NEW_BUILD_NAME-$NEW_BUILD_VER
ls -l /tmp/$NEW_BUILD_NAME-*
ls -l ~/ffp_0.7_armv5/packages/$NEW_BUILD_NAME-*
NEW_BUILD_NR=0

cd /ffp/home/root/compile/$NEW_BUILD_NAME_AND_VER
~/x.sh ffpg-all
./configure --help > configure.help.txt

#additional modules
#+nginx-dav-ext-module
#+ngx_devel_kit-0.2.19
#+lua-nginx-module-0.9.16rc3
#+echo-nginx-module-0.58
#+rds-json-nginx-module-0.14
#+drizzle-nginx-module-0.1.9
#+set-misc-nginx-module-0.29
#
#--with-pcre-jit -> must be the last

./configure --prefix=/ffp --conf-path=/ffp/etc/nginx/nginx.conf --error-log-path=/ffp/log/nginx-error.log --pid-path=/ffp/var/run/nginx.pid --user=nobody --group=nobody --with-file-aio --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-perl=/ffp/bin/perl --http-log-path=/ffp/log/nginx-access.log --http-client-body-temp-path=/ffp/tmp/nginx/client-body --http-proxy-temp-path=/ffp/tmp/nginx/proxy --http-fastcgi-temp-path=/ffp/tmp/nginx/fastcgi --http-uwsgi-temp-path=/ffp/tmp/nginx/uwsgi --http-scgi-temp-path=/ffp/tmp/nginx/scgi --with-stream --with-stream_ssl_module --with-cc=/ffp/bin/cc --with-cpp=/ffp/bin/cpp --with-cpu-opt=armv5te --with-debug --add-module=$HOME/compile/nginx-modules/nginx-dav-ext-module --add-module=$HOME/compile/nginx-modules/ngx_devel_kit-0.2.19 --add-module=$HOME/compile/nginx-modules/set-misc-nginx-module-0.29 --add-module=$HOME/compile/nginx-modules/drizzle-nginx-module-0.1.9 --add-module=$HOME/compile/nginx-modules/echo-nginx-module-0.58 --add-module=$HOME/compile/nginx-modules/rds-json-nginx-module-0.14 --add-module=$HOME/compile/nginx-modules/lua-nginx-module-0.9.16rc3 --with-pcre --with-pcre-jit

#ERROR (lua-nginx-module-0.9.16rc1)
	ngx_http_lua_initworkerby.c:(.text+0x2b8): undefined reference to `ngx_http_set_connection_log'
	objs/addon/src/ngx_http_lua_timer.o: In function `ngx_http_lua_timer_handler':
	ngx_http_lua_timer.c:(.text+0x4c0): undefined reference to `ngx_http_set_connection_log'
#SOLUTION
	sed -i s/"ngx_http_set_connection_log"/"ngx_set_connection_log"/ nginx-modules/lua-nginx-module-0.9.16rc1/src/ngx_http_lua_timer.c
	sed -i s/"ngx_http_set_connection_log"/"ngx_set_connection_log"/ nginx-modules/lua-nginx-module-0.9.16rc1/src/ngx_http_lua_initworkerby.c

#ERROR (drizzle-nginx-module-0.1.8)
	/ffp/home/root/compile/nginx-modules/drizzle-nginx-module-0.1.9/src/ngx_http_drizzle_util.c:607:13: error: 'ngx_http_upstream_state_t' has no member named 'response_sec'
		 u->state->response_sec = tp->sec;
				 ^
	/ffp/home/root/compile/nginx-modules/drizzle-nginx-module-0.1.8/src/ngx_http_drizzle_util.c:608:13: error: 'ngx_http_upstream_state_t' has no member named 'response_msec'
		 u->state->response_msec = tp->msec;
#SOLUTION
	#Replace any "->response_msec" with "->response_time".
	#Comment any line containing: "->response_sec =".
	#Replace any "&& u->state->response_time" with "&& u->state->response_time".
	#Do the above replacements/comments using these commands:
	sed -i s/"\s\s\su->state->response_sec"/"\/\/u->state->response_sec"/g /ffp/home/root/compile/nginx-modules/drizzle-nginx-module-0.1.8/src/ngx_http_drizzle_util.c
	sed -i s/"u->state->response_msec"/"u->state->response_time"/g /ffp/home/root/compile/nginx-modules/drizzle-nginx-module-0.1.8/src/ngx_http_drizzle_util.c
	sed -i s/"u->state->response_sec"/"u->state->response_time"/g /ffp/home/root/compile/nginx-modules/drizzle-nginx-module-0.1.8/src/ngx_http_drizzle_util.c

nohup /ffp/bin/make -C ~/compile/$NEW_BUILD_NAME_AND_VER &
renice -11 `pidof cc1plus` -p `pidof make` -p `pidof as` -p `pidof ld` -p `pidof configure` -p `pidof cc1` -p `pidof ccmake`
tail -f nohup.out

#directories required by nginx in order to run with default settings
mkdir -p /ffp/tmp/nginx/client-body
mkdir -p /ffp/tmp/nginx/proxy
mkdir -p /ffp/tmp/nginx/fastcgi
mkdir -p /ffp/tmp/nginx/uwsgi
mkdir -p /ffp/tmp/nginx/scgi

rm -r $HOME/temp/$NEW_BUILD_NAME_AND_VER
make install DESTDIR=$HOME/temp/$NEW_BUILD_NAME_AND_VER
cd $HOME/temp/$NEW_BUILD_NAME_AND_VER
makepkg $NEW_BUILD_NAME $NEW_BUILD_VER $NEW_BUILD_NR
cp -v /tmp/$NEW_BUILD_NAME-$NEW_BUILD_VER-arm-$NEW_BUILD_NR.txz ~/ffp_0.7_armv5/packages/
funpkg -q $NEW_BUILD_NAME
funpkg -i ~/apache-htdocs/ffp_0.7_armv5/packages/$NEW_BUILD_NAME-$NEW_BUILD_VER-arm-$NEW_BUILD_NR.txz

Compiling nginx 1.9.0

#See https://adrhc.go.ro/wordpress/common-commands-when-building/ for building environment, x.sh script and other things not defined here.
#Before starting do declare the environment variables specified to the link above.

NEW_BUILD_NAME=nginx
NEW_BUILD_VER=1.9.0
NEW_BUILD_NAME_AND_VER=$NEW_BUILD_NAME-$NEW_BUILD_VER
ls -l /tmp/$NEW_BUILD_NAME-*
ls -l ~/ffp_0.7_armv5/packages/$NEW_BUILD_NAME-*
NEW_BUILD_NR=1

cd /ffp/home/root/compile/nginx-1.9.0
~/x.sh ffpg
./configure --help > configure.help.txt

#additional modules
#+nginx-dav-ext-module
#+ngx_devel_kit-0.2.19
#+lua-nginx-module-0.9.16rc1
#+echo-nginx-module-0.57
#+rds-json-nginx-module
#+drizzle-nginx-module
#
#--with-pcre-jit -> must be the last

./configure --prefix=/ffp --conf-path=/ffp/etc/nginx/nginx.conf --error-log-path=/ffp/log/nginx-error.log --pid-path=/ffp/var/run/nginx.pid --user=nobody --group=nobody --with-file-aio --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-perl=/ffp/bin/perl --http-log-path=/ffp/log/nginx-access.log --http-client-body-temp-path=/ffp/tmp/nginx/client-body --http-proxy-temp-path=/ffp/tmp/nginx/proxy --http-fastcgi-temp-path=/ffp/tmp/nginx/fastcgi --http-uwsgi-temp-path=/ffp/tmp/nginx/uwsgi --http-scgi-temp-path=/ffp/tmp/nginx/scgi --with-cc=/ffp/bin/cc --with-cpp=/ffp/bin/cpp --with-cpu-opt=armv5te --with-debug --add-module=$HOME/compile/nginx-modules/nginx-dav-ext-module --add-module=$HOME/compile/nginx-modules/ngx_devel_kit-0.2.19 --add-module=$HOME/compile/nginx-modules/drizzle-nginx-module --add-module=$HOME/compile/nginx-modules/echo-nginx-module-0.57 --add-module=$HOME/compile/nginx-modules/rds-json-nginx-module --add-module=$HOME/compile/nginx-modules/lua-nginx-module-0.9.16rc1 --with-pcre --with-pcre-jit

ERROR
	ngx_http_lua_initworkerby.c:(.text+0x2b8): undefined reference to `ngx_http_set_connection_log'
	objs/addon/src/ngx_http_lua_timer.o: In function `ngx_http_lua_timer_handler':
	ngx_http_lua_timer.c:(.text+0x4c0): undefined reference to `ngx_http_set_connection_log'
SOLUTION
	sed -i s/"ngx_http_set_connection_log"/"ngx_set_connection_log"/ nginx-modules/lua-nginx-module-0.9.16rc1/src/ngx_http_lua_timer.c
	sed -i s/"ngx_http_set_connection_log"/"ngx_set_connection_log"/ nginx-modules/lua-nginx-module-0.9.16rc1/src/ngx_http_lua_initworkerby.c

nohup /ffp/bin/make -C ~/compile/$NEW_BUILD_NAME_AND_VER &
renice -11 `pidof cc1plus` -p `pidof make` -p `pidof as` -p `pidof ld` -p `pidof configure` -p `pidof cc1` -p `pidof ccmake`
tail -f nohup.out

#directories required for nginx to run with default settings
mkdir -p /ffp/tmp/nginx/client-body
mkdir -p /ffp/tmp/nginx/proxy
mkdir -p /ffp/tmp/nginx/fastcgi
mkdir -p /ffp/tmp/nginx/uwsgi
mkdir -p /ffp/tmp/nginx/scgi

rm -r $HOME/temp/$NEW_BUILD_NAME_AND_VER
make install DESTDIR=$HOME/temp/$NEW_BUILD_NAME_AND_VER
cd $HOME/temp/$NEW_BUILD_NAME_AND_VER
makepkg $NEW_BUILD_NAME $NEW_BUILD_VER $NEW_BUILD_NR
cp -v /tmp/$NEW_BUILD_NAME-$NEW_BUILD_VER-arm-$NEW_BUILD_NR.txz ~/ffp_0.7_armv5/packages/
funpkg -q $NEW_BUILD_NAME
funpkg -i ~/apache-htdocs/ffp_0.7_armv5/packages/$NEW_BUILD_NAME-$NEW_BUILD_VER-arm-$NEW_BUILD_NR.txz

nginx autoindex and apaxy

# I advise you to download apaxy + http://adrhc.go.ro/public/apaxy_for_nginx.js 
# then replace the urls below with the ones for your server.
# Possible values for:
# defaultSortProperty (string): "name", "parsedDate", "size"
# isDescSort (boolean): true/false
# apaxyIconsRoot (string): the root of apaxy icons dir (e.g. /apaxy/theme/icons/ -> ending slash matters!)
autoindex				on;
autoindex_exact_size	off;
add_before_body			http://adrhc.go.ro/apaxy-20150401/theme/header.html;
add_after_body			http://adrhc.go.ro/apaxy-20150401/theme/footer.html;
sub_filter				</body>	'<link href="http://adrhc.go.ro/apaxy-20150401/theme/style.css" rel="stylesheet"><script src="http://adrhc.go.ro/public/apaxy_for_nginx.js"></script><script>apaxyPatchForNginx.setDescSort(false);apaxyPatchForNginx.setDefaultSortProperty("name");apaxyPatchForNginx.setApaxyIconsRoot("http://adrhc.go.ro/apaxy-20150401/theme/icons/");apaxyPatchForNginx.doApaxy();</script></body>';
	sub_filter_last_modified	on;