陰符經與自動化睡中收入第一原則及Dynamic Serving優化手機頁麵

2019-08-20 约 1512 字 预计阅读 4 分钟

有一段時間沒有發帖了。這段時間在找Prebid Header Bidding的合作公司,一些大公司根本不理會我這種中小網站,寫信過去連個水泡都沒有,由此也可以想象到互聯網廣告的巨大吸金力。

繼而又想到自動化睡中收入的主題。

睡中收入

所謂睡中收入,也就是睡覺中、旅遊中、遊戲中、看碟中仍然能夠自動產生的收入。

如何取得各人有各法,有寫書版權、房租收入、網站廣告、Youtuber等等諸法,於我這種知天命而無甚財運的人,能獲得中產階級偏上的自動化收入,有能力齊家,有時間修身就很不錯,也算是此生處於這個信息時代的一個福報。

今天突然想到陰符經的幾句話


天之無恩而大恩生,迅雷烈風,莫不蠢然,至樂性餘,至靜性廉。天之至私,用之至公,禽之製在氣。

天似無恩而有大恩,迅雷烈風,孕育蠢蠢而動的生機。談到這裏,讀者可以試一試手機app白噪音,有雷聲風聲,遇到陰氣重的地方,放之可漸漸陽氣生發。

保持至樂至靜,常覺有餘,而無貪愛。

天之至私,用之至公。此之謂似分實合的世界,即天人合一與All is One。

禽之製在氣, 擒之通假,掌握。其要點在於氣,氣乃是交流。天人合一之要點就是氣,身中之氣與萬物之氣並無二致。其規律就是流轉不息。

故此自動化睡中收入的第一原則就是:

你付出價值(氣)給世界,世界會回饋價值(氣)給你


Dynamic Serving優化手機頁麵

為什麼要做這個呢,因為我要提供價值給網站客戶,令他們訪問更快。

Google也是身體力行這個原則的公司,故此他們有手機優先的搜索引擎排名規則。

前幾年對手機用戶的策略是采用Responsive design。就是一個網頁電腦版和手機版都做了,自動顯示合適的頁麵。

而 Dynamic Serving則是在服務器端就判斷用戶的設備,再將合適的頁麵呈現給用戶。其優點就是頁麵更小,尤其對手機用戶,可以省掉大量針對電腦用戶的代碼,可以大幅提高速度及用戶體驗。

Google的說明提到要使用Vary http header技術

nginx缺省是沒有這個選項,需要安裝ngx_headers_more

考慮到下次可能還需要在其他項目中設置,具體一點記錄一下:

先搞清已經安裝的nginx版本

sudo nginx -V
把出來的參數拷貝在一個文件裏備用,如下

然後下載同一版本的nginx

wget 'http://nginx.org/download/nginx-1.14.0.tar.gz'
tar -xzvf nginx-1.14.0.tar.gz
cd nginx-1.14.0/
./configure --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-FIJPpj/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --add-dynamic-module=/path/headers-more-nginx-module-0.33

一路上可能會要求裝不少插件,因為nginx以前不是編譯安裝的。

install libgd-dev in case of this error:
./configure: error: the HTTP image filter module requires the GD library.
install libgeoip-dev in case of:
./configure: error: the GeoIP module requires the GeoIP library.
install libssl-dev in case of:
./configure: error: SSL modules require the OpenSSL library.
install libpcre++-dev in case of:
./configure: error: the HTTP rewrite module requires the PCRE library.
install libxslt1-dev in case of:
./configure: error: the HTTP XSLT module requires the libxml2/libxslt

運行成功後出來結果,看到modules的path是:

nginx modules path: "/usr/lib/nginx/modules"
make module

然後將ngx_http_headers_more_filter_module.so拷貝到上麵的path裏

編輯nginx.conf

...
load_module modules/ngx_http_headers_more_filter_module.so;
...
http{ ...
#gzip_vary on;
more_set_headers -s 200 'Vary: Accept-Encoding, User-Agent';
,,,}

編輯sites-avaible裏的網站配置文件

map $geoip_country_code $preferred_upstream {
    default eu;
    US us;
}

map $geoip_country_code $preferred_upstream_mp {
    default eum;
    US usm;
}

upstream us {
    server unix:/path/us.sock;
}

upstream eu {
    server unix:/path/eu.sock;
}

upstream usm {
    server unix:/path/usm.sock;
}

upstream eum {
    server unix:/path/eum.sock;
}

server {
    ....
    location @fallback {
        # add trailing slash if url has no dot in it
        rewrite ^/([^\.]*[^/])$ /$1/ permanent;
        include     uwsgi_params;
        set $mobile_rewrite do_not_perform;

        if ($http_user_agent ~* '(iPhone|iPod|iPad|Android|BlackBerry|webOS|Windows Phone)') {
            set $mobile_rewrite perform;
        }

        if ($mobile_rewrite = do_not_perform) {
            uwsgi_pass $preferred_upstream;
            break;
        }

        if ($mobile_rewrite = perform) {
            uwsgi_pass $preferred_upstream_mp;
            break;
        }

        .......        
    }
    ...
}

這樣網站就將手機用戶分流到不同的socket。

剛開始這樣操作還老有問題,手機訪問出電腦版,電腦訪問出手機版。又研究了半天,發現是django的cache有問題,將memcached停用就解決問題了。

用pagespeed測試一下,原來隻有30分左右的手機網頁速度一下跳到了90分。


寫這個帖子的時候處理郵件又發現有一個命令,隨機生成包含各種字符,記錄到這裏

tr -cd '[:alpha:]' < /dev/urandom | fold -w20 | head -200000 > file.txt

20個字符一行,共200000行,輸出到file.txt


Tags: 陰符經

author

Jesse Lau

網名遁去的一,簡稱遁一。2012年定居新西蘭至今,自由職業者。手搓的GPTs
本文采用知識共享署名 4.0 國際許可協議進行許可。簡而言之,可隨意轉發轉載,轉載請注明出處。


留点评论吧: