プライムストラテージー株式会社が提供するkusanagiがレンタルサーバーで標準で搭載されるようになった。
Kusanagiがデビューしてからもう5年の月日が経っている。
Kusanagiのドキュメント通りにプロビジョンを行えば、ほとんど何もせずに高速でWordPressが動作する環境を手にいれることができる。
これが、オープンイノベーションのすごいところだ。
みんなが便利で世の中に役に立つために技術を公開してくれている。
WordPressのサイトは、全世界のサイトの1/3以上を占めるようになった。
kusanagiの良いところは、キャッシュ機構を利用してある程度ページビューまでは、1台のサーバーで賄うことができると言うことである。
サーバーのスペックにもよるが、1台のサーバーで月間1000万PVくらいは余裕で捌くことができるのではないかと思う。
だからとって、サーバーの中身や動作がわからなければ有料でプライムストラテージ株式会社にお願いすることになる。
そうでなければ、ゼロから自分たちでサーバーを構築するのか?という話になる。
サーバーを構築するために予算で1000万円をかけれるのであればそれでもいいかもしれない。
当たりまえだが、制作会社や開発会社は他社が作ったサーバーやシステムをすごく嫌がる。
お客さんにとって何が一番のメリットかと言うことを考えた場合、
特殊なものではなく、標準的なものでそろえることが、一番安上がりで一番安全で早いと言うことを覚えておいたほうがいい。
まずは、 nginxの設定ファイルがどこにあるかということだが、
nginxの設定ファイルを確認する。
nginxのファイルの位置は、下記にファイルが作成される。
/etc/nginx/conf.d/
プロビジョン名.conf
プロビジョン名_ssl.conf
が作成される。
そして、confファイルにSSLの設定やログ周り、キャッシュ周りの設定、nginxの設定がすべて書かれていると言うことがわかる
vi プロビジョン名_ssl.conf
1 #=======================================
2 # tabataatsuyoshi.com SSL
3 #---------------------------------------
4
5 server {
6 listen 443 ssl http2;
7 server_name tabataatsuyoshi.com www.tabataatsuyoshi.com;
8
9 ssl_certificate /etc/letsencrypt/live/tabataatsuyoshi.com/fullchain.pem;
10 ssl_certificate_key /etc/letsencrypt/live/tabataatsuyoshi.com/privkey.pem;
11 ssl_dhparam /etc/kusanagi.d/ssl/dhparam.key;
12
13 ssl_session_tickets on;
14 ssl_session_ticket_key /etc/kusanagi.d/ssl_sess_ticket.key;
15
16 ssl_session_cache shared:SSL:1m;
17 ssl_session_timeout 5m;
18
19 #ssl_ct on;
20 #ssl_ct_static_scts /etc/pki/tls/certs/scts;
21
22 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
23
25
26 ssl_prefer_server_ciphers on;
27
28 ## OCSP stapling
29 #ssl_stapling on;
30 #ssl_stapling_verify on;
31 #resolver 8.8.4.4 8.8.8.8 valid=300s;
32 #resolver_timeout 10s;
33
34 access_log /home/kusanagi/tabataatsuyoshi.com/log/nginx/ssl_access.log main;
35 error_log /home/kusanagi/tabataatsuyoshi.com/log/nginx/ssl_error.log warn;
36
37 charset UTF-8;
38 client_max_body_size 16M;
39 root /home/kusanagi/tabataatsuyoshi.com/DocumentRoot;
40 index index.php index.html index.htm;
41 rewrite /wp-admin$ $scheme://$host$uri/ permanent;
42
43 location / {
44 try_files $uri $uri/ /index.php?$args;
45 }
46
47 location = /favicon.ico {
48 log_not_found off;
49 access_log off;
50 }
51
52 location ~* /\.well-known {
53 allow all;
54 }
55
56 location ~* /\. {
57 deny all;
58 }
59
60 location ~* /(?:uploads|files)/.*\.php$ {
61 deny all;
62 }
63
64 # Redirect for SuperPWA
65 rewrite ^/superpwa-manifest(-[0-9]+)?.json$ /index.php?superpwa-manifest-$1.json last;
66 rewrite ^/OneSignalSDKWorker.js.php$ /index.php?OneSignalSDKWorker.js-$1.php last;
67 rewrite ^/superpwa-sw(-[0-9]+)?.js$ /index.php?superpwa-sw.js last;
68
69 #include templates.d/multisite.conf;
70
71 location ~* \.(jpg|jpeg|gif|png|css|js|swf|ico|pdf|svg|eot|ttf|woff)$ {
72 expires 60d;
73 access_log off;
74 }
77 satisfy any;
78 allow 0.0.0.0/0;
79 allow 127.0.0.1;
80 deny all;
81 auth_basic "basic authentication";
82 auth_basic_user_file "/home/kusanagi/.htpasswd";
83 location ~ [^/]\.php(/|$) {
84 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
85 if (!-f $document_root$fastcgi_script_name) {
86 return 404;
87 }
88 fastcgi_pass 127.0.0.1:9000;
89 fastcgi_index index.php;
90 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
91 include fastcgi_params;
92 fastcgi_buffers 256 128k;
93 fastcgi_buffer_size 128k;
94 fastcgi_intercept_errors on;
95 fastcgi_read_timeout 120s;
96 }
97 }
98
99 location ~ [^/]\.php(/|$) {
100 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
101 if (!-f $document_root$fastcgi_script_name) {
102 return 404;
103 }
104 fastcgi_pass 127.0.0.1:9000;
105 fastcgi_index index.php;
106 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
107 include fastcgi_params;
108 fastcgi_buffers 256 128k;
109 fastcgi_buffer_size 128k;
110 fastcgi_intercept_errors on;
111 fastcgi_read_timeout 120s;
112 #add_header Strict-Transport-Security "max-age=31536000";
113
114 set $do_not_cache 1; ## page cache
115 set $device "pc";
116
117 if ($request_method = POST) {
118 set $do_not_cache 1;
119 }
120
121 if ($query_string != "") {
122 set $do_not_cache 1;
123 }
124
125 if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
126 set $do_not_cache 1;
127 }
128
129 if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
130 set $do_not_cache 1;
131 }
132
133 if ($http_user_agent ~* " Android |\(iPad|Android; Tablet; .+Firefox") {
134 set $device "tablet";
135 }
136
137 if ($http_user_agent ~* " Android .+ Mobile |\(iPhone|\(iPod|IEMobile|Android; Mobile; .+Firefox|Windows Phone") {
138 set $device "smart";
139 }
140
141 fastcgi_cache wpcache;
142 fastcgi_cache_key "$device:$request_method:$scheme://$host$request_uri";
143 fastcgi_cache_valid 200 10m;
144 fastcgi_no_cache $do_not_cache;
145 fastcgi_cache_bypass $do_not_cache;
146
147 add_header X-F-Cache $upstream_cache_status;
148 add_header X-Signature KUSANAGI;
149 }
150
151 location ~ /fcache-purge/([^/]+)(/.*) {
152 allow 127.0.0.1;
153 deny all;
154 fastcgi_cache_purge wpcache "$1:GET:$scheme://$host$2";
155 }
156 }
157
158
それでは、簡単にconfファイルを見てみよう。
SSL設定の確認
kusanagiでは、めんどうなSSLの設定もコマンド一発で反映される。
しかもSSLの費用は無料である。
kusanagi ssl --email (自分のメールアドレス) (プロファイル名)
そして、その設定は、9行目から12行目のnginxのconfファイルに反映される。
9 ssl_certificate /etc/letsencrypt/live/tabataatsuyoshi.com/fullchain.pem;
10 ssl_certificate_key /etc/letsencrypt/live/tabataatsuyoshi.com/privkey.pem;
11 ssl_dhparam /etc/kusanagi.d/ssl/dhparam.key;
http→httpsへのリダイレクト
以下のコマンドで、httpでアクセスがあった場合、httpsにリダイレクトをかけてくれます。
kusanagi ssl --https redirect (プロファイル名)
ログファイルの確認
ログの場所ですが、
/home/kusanagi/プロビジョング名/log以下にファイルが作られる。
34 access_log /home/kusanagi/tabataatsuyoshi.com/log/nginx/ssl_access.log main;
35 error_log /home/kusanagi/tabataatsuyoshi.com/log/nginx/ssl_error.log warn;
nginxをリブートしたいときは
KUSNAGAI の場合は、以下のコマンドで PHP (PHP-FPM), nginx の再起動を同時に行ってくれます。
kusanagi restart
【参考サイト】
https://kusanagi.tokyo/document/
https://crieit.net/posts/KUSANAGI-PHP7-nginx
コメント