Nginx with geoip2, pagespeed & php-fpm
714
This image is created to have geoip2 and Google pagespeed module support for Nginx. It also includes php-fpm installation. Nginx was not compiled with SSL features so it can't be used to serve HTTPS pages.
Nginx 1.12.2 zlib 1.2.11 pcre 8.41 pagespeed 1.12.34-2-stable ngx_http_geoip2_module (version 2 : https://github.com/leev/ngx_http_geoip2_module)
php7.0-fpm php7.0-curl php-geoip php7.0-mbstring php7.0-mcrypt php7.0-opcache php7.0-mysql php7.0-pgsql php7.0-xml php redis [install as pear package] php composer
In addition to these, the image contains official Maxmind geoipupdate (https://github.com/maxmind/geoipupdate) and a cron file was added as /etc/cron.d/geoip_update.
geoip default configuration is located at /usr/local/etc/GeoIP.conf. You can use your own credentials to get both geoip and geoip2 databases by modifying this file.
A sample nginx and php-fpm pool conf was added : /etc/nginx/nginx.conf /etc/php/7.0/fpm/pool.d/www.conf
The default root folder for nginx is defined as /var/www/htdocs. geoip2 configuration in nginx.conf was commented out. For google pagespeed, some default filters/settings was enabled in nginx.conf.
For PHP setup, clear_env parameter was set to "No". Because without this option, to pass environmental variables nginx.conf must be modified to include fastcgi params as environmental variables. If you are using AWS Elastic Beanstalk, with this setting, you can set environmental variables with aws cli or aws web console for EB environment.
To start php processes you can use init scripts [I could not find better way to do it] and then you can start nginx process by using the binary located at /usr/share/nginx/sbin/nginx.
You can find the contents of sample configuration files below :
daemon off;
user www-data;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 200M;
# logs
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# gzip
gzip on;
gzip_disable "msie6";
#geoip
#geoip2 /usr/share/GeoIP/GeoIP2-Country.mmdb {
# $MM_COUNTRY_CODE2 source=$remote_addr country iso_code;
# $MM_COUNTRY_NAME2 country names en;
#}
#geoip2 /usr/share/GeoIP/GeoIP2-City.mmdb {
# $MM_COUNTRY_CODE country iso_code;
# $MM_COUNTRY_NAME country names en;
# $MM_REGION_CODE subdivisions 0 iso_code;
# $MM_CITY_NAME city names en;
#}
#geoip2 /usr/share/GeoIP/GeoIP2-ISP.mmdb {
# $MM_ASORG autonomous_system_organization;
# $MM_ISP isp;
# $MM_ORG organization;
#}
#page speed
pagespeed StatisticsPath /ngx_pagespeed_statistics;
pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics;
pagespeed MessagesPath /ngx_pagespeed_message;
pagespeed ConsolePath /pagespeed_console;
pagespeed AdminPath /pagespeed_admin;
pagespeed GlobalAdminPath /pagespeed_global_admin;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed EnableCachePurge on;
pagespeed RewriteLevel PassThrough;
# filters
pagespeed EnableFilters combine_css,remove_comments,collapse_whitespace;
pagespeed EnableFilters rewrite_css,rewrite_javascript;
pagespeed EnableFilters prioritize_critical_css;
pagespeed EnableFilters make_google_analytics_async;
pagespeed EnableFilters make_show_ads_async;
#pagespeed EnableFilters recompress_images;
#pagespeed EnableFilters resize_mobile_images,inline_preview_images,rewrite_images;
#pagespeed EnableFilters convert_jpeg_to_webp;
#pagespeed EnableFilters convert_to_webp_lossless;
#pagespeed EnableFilters resize_rendered_image_dimensions;
#pagespeed EnableFilters extend_cache;
#pagespeed ImageMaxRewritesAtOnce 1;
# disabled
#pagespeed DisableFilters extend_cache;
server {
listen 80;
server_name _;
root /var/www/htdocs;
#realip
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
#rewrite
if (!-f $request_filename) {
rewrite ^/favicon.ico /favicon.ico break;
rewrite ^/?(.*)$ /index.php?request=$1 break;
}
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
# php
location ~ \.php$ {
#fastcgi_param MM_COUNTRY_CODE $MM_COUNTRY_CODE;
#fastcgi_param MM_COUNTRY_NAME $MM_COUNTRY_NAME;
#fastcgi_param MM_REGION_CODE $MM_REGION_CODE;
#fastcgi_param MM_CITY_NAME $MM_CITY_NAME;
#fastcgi_param MM_ASORG $MM_ASORG;
#fastcgi_param MM_ISP $MM_ISP;
#fastcgi_param MM_ORG $MM_ORG;
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_intercept_errors off; # display errors use only for testing
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_ignore_client_abort off;
fastcgi_read_timeout 100;
fastcgi_param SERVER_NAME $host;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_pass_header X-Forwarded-For;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# htacces
location ~ /\.ht {
deny all;
}
}
}
[www]
user = www-data
group = www-data
listen = /run/php/php7.0-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 20
pm.start_servers = 6
pm.min_spare_servers = 4
pm.max_spare_servers = 8
request_terminate_timeout = 300
catch_workers_output = yes
php_flag[display_errors] = off
php_flag[short_open_tag] = On
php_admin_value[error_log] = /var/log/php/error.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 100M
clear_env = No
Content type
Image
Digest
Size
105.5 MB
Last updated
over 8 years ago
docker pull uguraslan/nginx-g2gpf:v11