{"id":5754,"date":"2015-01-01T14:31:49","date_gmt":"2015-01-01T06:31:49","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=5754"},"modified":"2023-06-23T13:12:58","modified_gmt":"2023-06-23T13:12:58","slug":"how-to-install-nginx-1-6-2-with-pagespeed-on-linux-centos-6","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-install-nginx-1-6-2-with-pagespeed-on-linux-centos-6\/","title":{"rendered":"How to Install Nginx 1.6.2 with PageSpeed on Linux CentOS 6"},"content":{"rendered":"<p>This article will show you the steps to install Nginx and ngx_pagespeed module on Linux CentOS 6 virtual private server (VPS). By using ngx_pagespeed, the speed of your website will be faster without installing any additional applications such as wordpress plugin and so on. This is because ngx_pagespeed have some Nginx module which rewrites your webpages to make them faster. Below steps has been tested on CentOS 6.5 and CentOS 6.6.<\/p>\n<p>1. Install nginx PageSpeed dependencies :<\/p>\n<pre>\nyum install gcc-c++ pcre-devel pcre-devel zlib-devel make unzip openssl-devel\n<\/pre>\n<p>2. Download and install ngx_pagespeed and PSOL (PageSpeed Optimization Libraries) source code :<\/p>\n<pre>\nmkdir -p \/etc\/nginx\/modules\ncd \/etc\/nginx\/modules\nwget https:\/\/github.com\/pagespeed\/ngx_pagespeed\/archive\/release-1.9.32.2-beta.zip\nunzip release-1.9.32.2-beta.zip\ncd ngx_pagespeed-release-1.9.32.2-beta\/\nwget https:\/\/dl.google.com\/dl\/page-speed\/psol\/1.9.32.2.tar.gz\ntar xzvf 1.9.32.2.tar.gz\n<\/pre>\n<p>3. Download NGINX :<\/p>\n<pre>\ncd \/etc\/nginx\/\nwget http:\/\/nginx.org\/download\/nginx-1.6.2.tar.gz\ntar xzvf nginx-1.6.2.tar.gz\ncd nginx-1.6.2\/\n<\/pre>\n<p>4. Compile and prepare environment for NGINX with ngx_pagespeed module support :<\/p>\n<pre>\n.\/configure --add-module=\/etc\/nginx\/modules\/ngx_pagespeed-release-1.9.32.2-beta --prefix=\/etc\/nginx --sbin-path=\/usr\/sbin\/nginx --conf-path=\/etc\/nginx\/nginx.conf --error-log-path=\/var\/log\/nginx\/error.log --http-log-path=\/var\/log\/nginx\/access.log --pid-path=\/var\/run\/nginx.pid --lock-path=\/var\/run\/nginx.lock --http-client-body-temp-path=\/var\/cache\/nginx\/client_temp --http-proxy-temp-path=\/var\/cache\/nginx\/proxy_temp --http-fastcgi-temp-path=\/var\/cache\/nginx\/fastcgi_temp --http-uwsgi-temp-path=\/var\/cache\/nginx\/uwsgi_temp --http-scgi-temp-path=\/var\/cache\/nginx\/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_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_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-file-aio --with-http_spdy_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-mail --with-mail_ssl_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'\n<\/pre>\n<p>At the end of installation, you will get the following message :<\/p>\n<pre>\n  nginx path prefix: \"\/etc\/nginx\"\n  nginx binary file: \"\/usr\/sbin\/nginx\"\n  nginx configuration prefix: \"\/etc\/nginx\"\n  nginx configuration file: \"\/etc\/nginx\/nginx.conf\"\n  nginx pid file: \"\/var\/run\/nginx.pid\"\n  nginx error log file: \"\/var\/log\/nginx\/error.log\"\n  nginx http access log file: \"\/var\/log\/nginx\/access.log\"\n  nginx http client request body temporary files: \"\/var\/cache\/nginx\/client_temp\"\n  nginx http proxy temporary files: \"\/var\/cache\/nginx\/proxy_temp\"\n  nginx http fastcgi temporary files: \"\/var\/cache\/nginx\/fastcgi_temp\"\n  nginx http uwsgi temporary files: \"\/var\/cache\/nginx\/uwsgi_temp\"\n  nginx http scgi temporary files: \"\/var\/cache\/nginx\/scgi_temp\"\n<\/pre>\n<p>Note : Keep this information as you will need it if you plan to uninstall the NGINX.<\/p>\n<p>Building the NGINX with ngx_pagespeed :<\/p>\n<pre>\nmake\n<\/pre>\n<p>Install NGINX with ngx_pagespeed to the system :<\/p>\n<pre>\nmake install\n<\/pre>\n<p>5. Create a Cache directory which will be written by Nginx.<\/p>\n<pre>\nmkdir \/var\/ngx_pagespeed_cache\nchown nginx:nginx \/var\/ngx_pagespeed_cache\n<\/pre>\n<p>6. Configure NGINX (nginx.conf) and turn on pagespeed module :<\/p>\n<pre>\n..\n..\npagespeed on;\npagespeed FileCachePath \/var\/ngx_pagespeed_cache;\n\n# enable CoreFilters\npagespeed RewriteLevel CoreFilters;\n\n# enable additional filter(s) selectively\npagespeed EnableFilters collapse_whitespace;\npagespeed EnableFilters lazyload_images;\npagespeed EnableFilters insert_dns_prefetch;\npagespeed EnableFilters prioritize_critical_css;\npagespeed EnableFilters collapse_whitespace;\n..\n..\n<\/pre>\n<p>7. Create an init script for Nginx.<\/p>\n<pre>\nvi \/etc\/init.d\/nginx\n<\/pre>\n<pre>\n#!\/bin\/sh\n#\n# nginx        Startup script for nginx\n#\n# chkconfig: - 85 15\n# processname: nginx\n# config: \/etc\/nginx\/nginx.conf\n# config: \/etc\/sysconfig\/nginx\n# pidfile: \/var\/run\/nginx.pid\n# description: nginx is an HTTP and reverse proxy server\n#\n### BEGIN INIT INFO\n# Provides: nginx\n# Required-Start: $local_fs $remote_fs $network\n# Required-Stop: $local_fs $remote_fs $network\n# Default-Start: 2 3 4 5\n# Default-Stop: 0 1 6\n# Short-Description: start and stop nginx\n### END INIT INFO\n\n# Source function library.\n. \/etc\/rc.d\/init.d\/functions\n\nif [ -L $0 ]; then\n    initscript=`\/bin\/readlink -f $0`\nelse\n    initscript=$0\nfi\n\nsysconfig=`\/bin\/basename $initscript`\n\nif [ -f \/etc\/sysconfig\/$sysconfig ]; then\n    . \/etc\/sysconfig\/$sysconfig\nfi\n\nnginx=${NGINX-\/usr\/sbin\/nginx}\nprog=`\/bin\/basename $nginx`\nconffile=${CONFFILE-\/etc\/nginx\/nginx.conf}\nlockfile=${LOCKFILE-\/var\/lock\/subsys\/nginx}\npidfile=${PIDFILE-\/var\/run\/nginx.pid}\nSLEEPMSEC=${SLEEPMSEC-200000}\nUPGRADEWAITLOOPS=${UPGRADEWAITLOOPS-5}\nRETVAL=0\n\nstart() {\n    echo -n $\"Starting $prog: \"\n\n    daemon --pidfile=${pidfile} ${nginx} -c ${conffile}\n    RETVAL=$?\n    echo\n    [ $RETVAL = 0 ] && touch ${lockfile}\n    return $RETVAL\n}\n\nstop() {\n    echo -n $\"Stopping $prog: \"\n    killproc -p ${pidfile} ${prog}\n    RETVAL=$?\n    echo\n    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}\n}\n\nreload() {\n    echo -n $\"Reloading $prog: \"\n    killproc -p ${pidfile} ${prog} -HUP\n    RETVAL=$?\n    echo\n}\n\nupgrade() {\n    oldbinpidfile=${pidfile}.oldbin\n\n    configtest -q || return\n    echo -n $\"Starting new master $prog: \"\n    killproc -p ${pidfile} ${prog} -USR2\n    echo\n\n    for i in `\/usr\/bin\/seq $UPGRADEWAITLOOPS`; do\n        \/bin\/usleep $SLEEPMSEC\n        if [ -f ${oldbinpidfile} -a -f ${pidfile} ]; then\n            echo -n $\"Graceful shutdown of old $prog: \"\n            killproc -p ${oldbinpidfile} ${prog} -QUIT\n            RETVAL=$?\n            echo\n            return\n        fi\n    done\n\n    echo $\"Upgrade failed!\"\n    RETVAL=1\n}\n\nconfigtest() {\n    if [ \"$#\" -ne 0 ] ; then\n        case \"$1\" in\n            -q)\n                FLAG=$1\n                ;;\n            *)\n                ;;\n        esac\n        shift\n    fi\n    ${nginx} -t -c ${conffile} $FLAG\n    RETVAL=$?\n    return $RETVAL\n}\n\n\nrh_status() {\n    status -p ${pidfile} ${nginx}\n}\n\n# See how we were called.\ncase \"$1\" in\n    start)\n        rh_status >\/dev\/null 2>&1 && exit 0\n        start\n        ;;\n    stop)\n        stop\n        ;;\n    status)\n        rh_status\n        RETVAL=$?\n        ;;\n    restart)\n        configtest -q || exit $RETVAL\n        stop\n        start\n        ;;\n    upgrade)\n        rh_status >\/dev\/null 2>&1 || exit 0\n        upgrade\n        ;;\n    condrestart|try-restart)\n        if rh_status >\/dev\/null 2>&1; then\n            stop\n            start\n        fi\n        ;;\n    force-reload|reload)\n        reload\n        ;;\n    configtest)\n        configtest\n        ;;\n    *)\n        echo $\"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}\"\n        RETVAL=2\nesac\n\nexit $RETVAL\n<\/pre>\n<pre>\nchmod 0755 \/etc\/init.d\/nginx\nchown root:root \/etc\/init.d\/nginx\n<\/pre>\n<p>8. Start nginx and make it autostart at boot :<\/p>\n<pre>\nservice nginx start\nchkconfig nginx on\n<\/pre>\n<p>9. Check NGINX version and installed modules :<\/p>\n<pre>\n$ nginx -V\nnginx version: nginx\/1.6.2\nbuilt by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)\nTLS SNI support enabled\nconfigure arguments: --add-module=\/etc\/nginx\/modules\/ngx_pagespeed-release-1.9.32.2-beta --prefix=\/etc\/nginx --sbin-path=\/usr\/sbin\/nginx --conf-path=\/etc\/nginx\/nginx.conf --error-log-path=\/var\/log\/nginx\/error.log --http-log-path=\/var\/log\/nginx\/access.log --pid-path=\/var\/run\/nginx.pid --lock-path=\/var\/run\/nginx.lock --http-client-body-temp-path=\/var\/cache\/nginx\/client_temp --http-proxy-temp-path=\/var\/cache\/nginx\/proxy_temp --http-fastcgi-temp-path=\/var\/cache\/nginx\/fastcgi_temp --http-uwsgi-temp-path=\/var\/cache\/nginx\/uwsgi_temp --http-scgi-temp-path=\/var\/cache\/nginx\/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_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_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-file-aio --with-http_spdy_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-mail --with-mail_ssl_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'\n<\/pre>\n<p>10. Testing the pagespeed module:<\/p>\n<pre>\ncurl -I http:\/\/www.ehowstuff.local\n<\/pre>\n<p>You should see X-Page-Speed version in the headers:<\/p>\n<pre>\nHTTP\/1.1 200 OK\nServer: nginx\nContent-Type: text\/html; charset=UTF-8\nConnection: keep-alive\nVary: Accept-Encoding\nX-Pingback: http:\/\/www.ehowstuff.local\/xmlrpc.php\nDate: Thu, 01 Jan 2015 06:41:14 GMT\n<strong>X-Page-Speed: 1.9.32.2-4321<\/strong>\nCache-Control: max-age=0, no-cache\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This article will show you the steps to install Nginx and ngx_pagespeed module on Linux CentOS 6 virtual private server (VPS). By using ngx_pagespeed, the speed of your website will&#8230;<\/p>\n","protected":false},"author":6,"featured_media":5538,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055],"tags":[1257,1605,1631,1933],"class_list":["post-5754","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","tag-centos-6-6","tag-nginx","tag-pagespeed","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5754","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=5754"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5754\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/5538"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=5754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=5754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=5754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}