#! Lum7671's Weblog
메모하거나 죽거나...
#! Lum7671's Weblog
Nginx Memo

기억하고 싶은 Nginx 메모

Add ngx_pagespeed module to Ubuntu 16.10

2017/06/15

설치

  • 자동 설치 시작
% bash <(curl -f -L -sS https://ngxpagespeed.com/install) --nginx-version latest

컴파일 옵션 추가

  • —with-http_v2_module —with-http_ssl_module” 컴파일 옵션 추가.
...
Extracting nginx...
About to build nginx.  Do you have any additional ./configure
arguments you would like to set?  For example, if you would like
to build nginx with https support give --with-http_ssl_module
If you don't have any, just press enter.
> --with-http_v2_module --with-http_ssl_module
...

NginX 설정

  • pagespeed module 설정 확인 (nginx.conf)
% cat /usr/local/nginx/conf/nginx.conf | grep "pagespeed"
...
    server {
        ...
        pagespeed on;
# https://developers.google.com/speed/pagespeed/module/system
        pagespeed FileCacheSizeKb            102400;
        pagespeed FileCacheCleanIntervalMs   3600000;
        pagespeed FileCacheInodeLimit        500000;
        pagespeed LRUCacheKbPerProcess     8192;
        pagespeed LRUCacheByteLimit        16384;
# pagespeed DefaultSharedMemoryCacheKB 50000;
        pagespeed FileCachePath /var/ngx_pagespeed_cache;
# pagespeed EnableFilters combine_css,combine_javascript;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
        location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
        location ~ "^/pagespeed_static/" { }
        location ~ "^/ngx_pagespeed_beacon$" { }
        ...
    }
...
  • http2 module 설정 확인 (nginx.conf)
% cat /usr/local/nginx/conf/nginx.conf | grep "http2"
...
    server {
        ...
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        ...
    }
...

Ubuntu Service 설정

  • nginx.service 수정 PIDFile과 nginx 실행 파일 위치 변경. /run/nginx.pid => /usr/local/nginx/logs/nginx.pid /usr/sbin/nginx => /usr/local/nginx/sbin/nginx
% cat /lib/systemd/system/nginx.service
[Service]
...
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /usr/local/nginx/logs/nginx.pid
...
  • nginx.service 실행
% sudo -s
% service nginx start

결과 확인

  • NginX 서비스 확인
  • http : httpie
% http --headers https://oh.mypi.co/
HTTP/1.1 200 OK
Cache-Control: max-age=0, no-cache
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Thu, 15 Jun 2017 03:26:52 GMT
Server: nginx/1.13.1       <===  NginX 버전 확인
Strict-Transport-Security: max-age=15768000
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Page-Speed: 1.11.33.4-0  <===  PageSpeed 버전 확인

2016/10/15

1. Update of Ubuntu packages

% alias agud # This is oh-my-zsh's ubuntu plug-in
agud='sudo apt-get update && sudo apt-get dist-upgrade'
% agud

2. Prepare for making deb

2.1 getting deb-source of nginx

% sudo apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev unzip
% mkdir ~/tmp/nginx_source
% cd ~/tmp/nginx_source
% apt-get source nginx
% apt-get build-dep nginx

2.2 setup of ngx_pagespeed

% mkdir ~/tmp/ngx_pagespeed
% cd ~/tmp/ngx_pagespeed
% ngx_version='1.11.33.4'
% http -d https://github.com/pagespeed/ngx_pagespeed/archive/release-%{ngx_version}-beta.tar.gz
% aunpack release-${ngx_version]-beta.tar.gz
% http -d https://dl.google.com/dl/page-speed/psol/${ngx_version}.tar.gz
% aunpack ${ngx_version}.tar.gz

3. Rebuild nginx-extras package from deb-source

3.1 Edit rules file for adding ngx_pagespeed module on deb-source of Nginx

% sudo vim ~/tmp/nginx_source/nginx-1.10.1/debian/rules
...
common_configure_flags := \
...
                        --add-module=$(HOME)/tmp/ngx_pagespeed/ngx_pagespeed-1.11.33.4-beta
...

3.2 Rebuild nginx

% cd ~/tmp/nginx_source/nginx-1.10.1
% sudo dpkg-buildpackage -b

4. Install nginx-extras

% cd ~/tmp/nginx_source
% sudo dpkg -i nginx-common_1.10.1-0ubuntu1_all.deb nginx-extras_1.10.1-0ubuntu1_amd64.deb

5. Hold nginx package

% sudo apt-mark hold nginx-extras

Add ngx_pagespeed module to Ubuntu 15.10

2016년 3월 6일 기준으로,

3개의 파일을 받는다. https://dl.google.com/dl/linux/mod-pagespeed/tar/beta/mod-pagespeed-beta-1.9.32.10-r7423.tar.bz2) https://github.com/pagespeed/ngx_pagespeed/archive/v1.9.32.10-beta.zip * http://nginx.org/download/nginx-1.9.12.tar.gz

참고 사이트: https://developers.google.com/speed/pagespeed/module/build_mod_pagespeed_from_source#prerequisites https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source#dependencies https://github.com/pagespeed/ngx_pagespeed/releases http://nginx.org/en/download.html * http://www.tecmint.com/install-mod_pagespeed-to-boost-apache-nginx-performance/

./generate.sh

1. Required

sudo apt-get install apache2 g++ python subversion gperf make devscripts fakeroot git curl
sudo apt-get install icu-devtools libicu-dev libapr1-dev libaprutil1-dev apache2-dev

net/instaweb/system/apr_mem_cache.cc:23:34: fatal error: apr_pools.h: No such file or directory

2. Mod_Pagespeed Compile

mkdir -p ~/bin
cd ~/bin
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

export PATH=$PATH:~/bin/depot_tools

cd
mkdir ~/mod_pagespeed    # Any directory is fine.
cd ~/mod_pagespeed
gclient config https://github.com/pagespeed/mod_pagespeed.git --unmanaged --name=src # depot_tools
git clone https://github.com/pagespeed/mod_pagespeed.git src
cd src

git checkout latest-stable
cd ..
gclient sync --force --jobs=1

cd ~/mod_pagespeed/src
~/mod_pagespeed/src % make AR.host=`pwd`/build/wrappers/ar.sh AR.target
=`pwd`/build/wrappers/ar.sh BUILDTYPE=Release

3. Ngx_Pagespeed - Nginx Module Complie

cd
NPS_VERSION=1.10.33.6
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip -O release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
tar -xzvf ${NPS_VERSION}.tar.gz  # extracts to psol/

4. Nginx Compile

cd
# check http://nginx.org/en/download.html for the latest version
NGINX_VERSION=1.9.12
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz

sudo chown -R nginx: nginx-1.9.12

cd nginx-${NGINX_VERSION}/
./configure --add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta \
--user=www-data \
--group=www-data \
--with-http_ssl_module \
--with-threads \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module

make
sudo make install

~/works/nginx-1.9.12 % MOD_PAGESPEED_DIR=&quot;$HOME/mod_pagespeed/src&quot; ./configure --add-module=$HOME/works/ngx_pagespeed-release-1.9.32.10-beta

5. Nginx Configure

cat /usr/local/nginx/conf/nginx.conf
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}
sudo vim /etc/nginx/sites-enabled/default
...
server {

#########################################
pagespeed on;

# https://developers.google.com/speed/pagespeed/module/system
pagespeed FileCacheSizeKb            102400;
pagespeed FileCacheCleanIntervalMs   3600000;
pagespeed FileCacheInodeLimit        500000;
pagespeed LRUCacheKbPerProcess     8192;
pagespeed LRUCacheByteLimit        16384;
# pagespeed DefaultSharedMemoryCacheKB 50000;

# Needs to exist and be writable by nginx.  Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;

# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
  add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
#########################################

listen 80 default_server;

6. Verify

% curl -D- https://oh.mypi.co/ | less
HTTP/1.1 200 OK
Server: nginx/1.9.12
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Strict-Transport-Security: max-age=15768000
Date: Sun, 06 Mar 2016 05:59:06 GMT
X-Page-Speed: 1.10.33.6-0
Cache-Control: max-age=0, no-cache

Linux Tips

기억하고 싶은 Linux 팁

용어, Shebang (Unix) Shebang (Unix) - Wikiwand 예) #!/usr/bin/env zsh /etc/crontab 출처 : Linux scheduler : Cron, At jobs - Kernel Talks # cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | |...

Read More
MacOS Tips

MacOS에서 기억하고 싶은 것

cron 설정 문제 crontab -e 로 설정을 하고 ‘wq’로 저장하면 아래와 같은 메세지가 나오면서 저장 되지 않는 문제가 있다. % crontab -e crontab: no crontab for userid - using an empty one crontab: temp file must be edited in place 해결1 - $HOME/.crontab % touch $HOME/.crontab # 파일 생성 % vim $HOME/.crontab # cron 등록 % crontab $HOME/.crontab # cron 적용 해결2 - $HOME/.vimrc Read More


Ubuntu Note

Ubuntu 에서 기억하고 싶은 내용

UFW (Uncomplicated Firewall) 1. 링크 UFW - Community Help Wiki init.d, update-rc.d 배경 : nginx를 사용해서 Apache2가 뜨지 않도록 함. pagespeed 를 사용하기 위해서 Apache2가 설치 돼있어야 함. 1. runlevel 확인 % runlevel N 5 N : 이전 runlevel 5 : 현재 runlevel 2. apache2 데몬 띄우지 않기 2.1 “KXX…” symbolic link 만들기. % ls -ald /etc/rc5.d/K01apache2 lrwxrwxrwx 1 root root 17 8월 20 2016 /etc/rc5.d/K01apache2 -> ../init.d/apache2 2.2 수정 내용 시스템에 적용하기. % sudo update-rc.d apache2 defaults 2.3 혹은, daemon disable % sudo...

Read More
Bookmarks

저장하고 싶은 site

Utils Free Password Manager Compatible with KeePass: KeeWeb : Free cross-platform password manager compatible with KeePass 개발 Zeal : Zeal is an offline documentation browser for software developers. LovelyDocs : Android app That is like Dash on Mac OS. intellij-idea-cheat-sheet : intellij’s cheat sheet for Dash. Hex Fiend : A fast and clever open source hex editor for Mac OS X. Introduction | Sed Stream EDitor : Sed Stream Editor 네트워크 HTTPie : a CLI, cURL-like tool for humans AXEL...

Read More
Xcode Memo

기억하고 싶은 Xcode 메모

Convert ‘Unicode Code Point’ to UTF-8 test.py #!/usr/bin/env python #-*- coding: utf-8 -*- import sys reload(sys) sys.setdefaultencoding('utf-8') foo = '\Uc11c\Ubc84\Uc5d0 \Ubb38\Uc81c\Uac00 \Ubc1c\Uc0dd\Ud588\Uc2b5\Ub2c8\Ub2e4.' print foo foo = foo.decode('raw_unicode_escape') foo = foo.lower() # replace('\U', '\u') print foo Read More


https, letsencrypt.org 와 nginx

letsencrypt를 이용해 https 사이트 만들기

인증서 갱신 (renew, certonly) crontab % sudo crontab -l # 2월, 4월, 6월, 8월, 10월, 12월 매 6일 새벽 4시 17분에 let's encript 갱신 17 4 6 2,4,6,8,10,12 * /opt/local/sbin/letsencrypt_renew.sh 참고 : /etc/crontab /opt/local/sbin/letsencrypt_renew.sh % cat /opt/local/sbin/letsencrypt_renew.sh #!/bin/sh # NginX Stop service nginx stop # or whatever your webserver is # LetsEncrypt Update /opt/local/letsencrypt/letsencrypt-auto certonly -w /var/www/html -d oh.mypi.co --force-renewal --no-self-upgrade --standalone LE_STATUS Read More


Aquamacs

Aquamacs 관련 메모

customizations.el 위치 : $HOME/Library/Preferences/Aquamacs\ Emacs/customizations.el PATH 설정 (setenv "PATH" (concat "/Users/1001028/bin" ":" "/usr/local/bin" ":" (getenv "PATH") ) ) PATH 확인 M-x getenv => PATH LANG=ko_KR.UTF-8 (setenv "LANG" (concat "ko_KR.UTF-8"...

Read More
Synology NAS

Synology NAS 메모

DSM 6.1 - Seagate IronWolf 씨게이트 아이언울프 헬스 매니지먼트 (IronWolf Health Management, IHM) 하드로 씨게이트 아이언울프를 사야 할 이유??? ㅎㅎ 링크 : DiskStation Manager 6.1 씨게이트와 시놀로지, 지능형 드라이브 진단 소프트웨어 출시 ::: 베타뉴스 씨게이트가 제공하는 최첨단 데이터 복구 기술은 물론, 주요 변수를 지속적으로 모니터링하고, 문제를 차단, 신속한 문제 해결 등 시놀로지 DSM에 장착된 드라이브를 관리한다. 온도나 습도처럼 NAS 운용 환경과 연관된 추가 정보를 수집해 발생할 수 있는 문제를 미리 예방할 수 있다. 아이언울프 헬스 매니지먼트는 드라이브 사용...

Read More
경력에 대한 생각

프로그래머의 경력에 대한 생각

장인이 있는 창착이나 공예와 같은 분야에서 경력이 쌓일수록 기술이 다듬어지고 빨라지고 기술 노하우도 늘어서 초급 기술자보다 고급 기술자와 격차가 눈에 띄게 많이 난다. 하지만, 컴퓨터 프로그래머로 고급 기술자가 되는 길은 명확하지 못한 것 같다. “넓고 얕게” 또는 “좁고 깊게” 보통 내 경력에 대해 얘기할 때, “넓고 얕게 알고 있다”라고 하는데 경력을 쌓는 방법으로는 이것도 한 방법이고, 그 반대인 좁고 깊게 아는 방법도 경력을 쌓는 방법이라고 생각이 된다. 분야 92학번 나이에 한국에서 프로그래머로 살아가는 것은 미래에 대한 알 수 없는 불안으로 계속해서 걱정을 하며 살았던 것 같다. 선배가 있으면 선배를...

Read More
  • 1
  • 2