Cara Compile Nginx Dari Source

Kenapa harus compile dari source? Karena ada modul yang tidak disertakan dalam repo Ubuntu, seperti modul mod_pagespeed. Langsung saja berikut ini langkah-langkah compile nginx dari source beserta 2 dynamic module, yakni nginx image-filter dan mod_pagespeed.

# image filter depend on libgd2
sudo apt install libgd2-xpm-dev 
sudo apt install libgd-dev

# download latest nginx
cd
wget http://nginx.org/download/nginx-1.13.0.tar.gz
tar zxf nginx-1.11.13.tar.gz
cd nginx-1.11.13/

# download pcre tools
cd
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
tar -zxf pcre-8.40.tar.gz
cd pcre-8.40
./configure
make
sudo make install

# download zlib
cd
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
sudo make install

# download openssl
cd
wget http://www.openssl.org/source/openssl-1.0.2f.tar.gz
tar -zxf openssl-1.0.2f.tar.gz
cd openssl-1.0.2f/
./Configure --prefix=/usr
./config
make
sudo make install

# compile mod_pagespeed
cd
NPS_VERSION=[check the release notes for the latest version]
NPS_VERSION=1.12.34.2
wget https://github.com/pagespeed/ngx_pagespeed/archive/v${NPS_VERSION}-beta.zip
unzip v${NPS_VERSION}-beta.zip
cd ngx_pagespeed-${NPS_VERSION}-beta/
psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
[ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL)
wget ${psol_url}
tar -xzvf $(basename ${psol_url}) # extracts to psol/

# compile nginx with 2 extra dynamic modules
cd nginx-1.11.13/
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-pcre=../pcre-8.40 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2f --with-http_ssl_module --with-stream --with-mail=dynamic --with-http_image_filter_module=dynamic --add-dynamic-module=../ngx_pagespeed-1.12.34.2-beta
make
sudo make install

Jalankan nginx dan lihat apakah modul sudah terpasang

sudo /usr/local/nginx/nginx -V

Tambahkan baris berikut di bagian paling atas di /usr/local/nginx.conf

load_module "modules/ngx_pagespeed.so";

Contoh nginx.conf

load_module "modules/ngx_pagespeed.so";

user www-data;
worker_processes 4;
pid logs/nginx.pid;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
 worker_connections 1024;
}


http { 
 
 include mime.types;
 default_type application/octet-stream;

 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
 # '$status $body_bytes_sent "$http_referer" '
 # '"$http_user_agent" "$http_x_forwarded_for"';

 #access_log logs/access.log main;

 sendfile on;
 #tcp_nopush on;

 #keepalive_timeout 0;
 keepalive_timeout 65;

 gzip on;
 gzip_disable "msie6";

 gzip_vary on;
 gzip_proxied any;
 gzip_comp_level 6;
 gzip_buffers 16 8k;
 gzip_http_version 1.1;
 gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;

 server {
 
 listen 80;
 server_name localhost;

 #charset koi8-r;

 #access_log logs/host.access.log main;

 location / {
 root html;
 index index.html index.htm;
 }

 #error_page 404 /404.html;

 # redirect server error pages to the static page /50x.html
 #
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root html;
 }

 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 #
 #location ~ \.php$ {
 # proxy_pass http://127.0.0.1;
 #}

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 #location ~ \.php$ {
 # root html;
 # fastcgi_pass 127.0.0.1:9000;
 # fastcgi_index index.php;
 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
 # include fastcgi_params;
 #}

 # deny access to .htaccess files, if Apache's document root
 # concurs with nginx's one
 #
 #location ~ /\.ht {
 # deny all;
 #}
 }


 # another virtual host using mix of IP-, name-, and port-based configuration
 #
 #server {
 # listen 8000;
 # listen somename:8080;
 # server_name somename alias another.alias;

 # location / {
 # root html;
 # index index.html index.htm;
 # }
 #}


 # HTTPS server
 #
 #server {
 # listen 443 ssl;
 # server_name localhost;

 # ssl_certificate cert.pem;
 # ssl_certificate_key cert.key;

 # ssl_session_cache shared:SSL:1m;
 # ssl_session_timeout 5m;

 # ssl_ciphers HIGH:!aNULL:!MD5;
 # ssl_prefer_server_ciphers on;

 # location / {
 # root html;
 # index index.html index.htm;
 # }
 #}

 include /etc/nginx/conf.d/*.conf;
 include /etc/nginx/sites-enabled/*;

 pagespeed FileCachePath "/var/cache/pagespeed/";
 pagespeed FileCacheSizeKb 102400;
 pagespeed FileCacheCleanIntervalMs 3600000;
 pagespeed FileCacheInodeLimit 500000;
 pagespeed EnableFilters prioritize_critical_css;
 pagespeed EnableFilters combine_css;
 pagespeed EnableFilters combine_javascript;
 pagespeed EnableFilters defer_javascript;
 pagespeed ImagePreserveURLs on;
 pagespeed EnableFilters recompress_jpeg;
 pagespeed EnableFilters recompress_png;
 pagespeed EnableFilters convert_jpeg_to_progressive;
 pagespeed SupportNoScriptEnabled false;

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s