Skip to content

Instantly share code, notes, and snippets.

@ym405nm
Last active July 1, 2017 03:02
Show Gist options
  • Save ym405nm/77308b073111f14fcad69eebf5c32a05 to your computer and use it in GitHub Desktop.
Save ym405nm/77308b073111f14fcad69eebf5c32a05 to your computer and use it in GitHub Desktop.
nginx の location 設定部分
# プラグインに対するアクセスを拒否する
location ^~ /wp-content/plugins/ {
access_log /var/log/nginx/plugins.log format;
error_log /var/log/nginx/plugins.log;
return 403;
}
# テーマに対するアクセスを拒否する
location ^~ /wp-content/themes/ {
access_log /var/log/nginx/themes.log format;
error_log /var/log/nginx/themes.log;
# デフォルトテーマはアクセスを許可し、それ以外を拒否
if ($request_uri !~ "twenty") {
return 403;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
# ログインに対するアクセスを拒否する
location ^~ /wp-login.php {
# ログインが行われる POST リクエストのみに絞る
if ($request_method ~ (POST)$ ){
access_log /var/log/nginx/login.log format;
return 403;
}
# それ以外は PHPを実行させる
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/wordpress$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment