こちらでWordPressを導入しました。が、構築のときに書いてあるようにnginxの設定は最低限しか入れてません。
WordPress用にnginxの設定も変更しましょう。
nginxの設定を変更する。
configファイルは、親をいじるのではなく、conf.dにちゃんと個別に作ってあげましょうね。 (でも親のdefault_serverは消して置かないとだめだよ)
$ vim /etc/nginx/conf.d/www.conf
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
server {
listen 80 default_server;
server_name localhost;
root /var/www/public_html/wordpress;
#auth_basic "Basic Auth";
#auth_basic_user_file /etc/nginx/basic/.htpasswd;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~* /wp-config.php {
deny all;
}
location /wp-content/plugins/akismet {
location ~ /wp-content/plugins/akismet/(.+/)?(form|akismet)\.(css|js)$ {
allow all;
}
location ~ /wp-content/plugins/akismet/(.+/)?(.+)\.(png|gif)$ {
allow all;
}
deny all;
}
location ~ \.php$ {
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
location ~ .*\.(js|css|png|gif|jpg|jpeg|svg|ico) {
access_log off;
expires 7d;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rootディレクトリを違う場所に置いているのであれば、適切な位置へ。 ベーシック認証のをコメントアウトしているので、もしベーシック認証を使う場合にはコメントアウトを外してパスファイルを使って下さい。
特殊な設定は入れず、gzipの圧縮などを入れておく。 open_file_cacheで配信コンテンツのファイル情報を残しているが、 超リアルタイムでなければ問題は無いよう設定。 client_max_body_sizeはアップロード制限を回避するため。 デフォルトでは容量が小さいので、20Mくらいあれば画像などの投稿は問題ないはず。
また、wp-config.phpにはDBのパスなど重要なことが書かれているので、 普通にはアクセスされないようになっていますが、webサーバーの設定でも弾いて起きましょう。 akismetの設定も入れておきます。
これで設定項目は完了。問題ないかチェックした後に読み直します。
$ nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ systemctl restart nginx


