LoginSignup
2
2

More than 3 years have passed since last update.

AWSに構築したWordPressのエラーページを変更してみた

Posted at

はじめに

AWSにWordPressを構築してみた
AWSに構築したWordPressに独自ドメインを割り当ててみた
AWSに構築したWordPressをhttps対応してみた
の続き。

構築した時に利用したWordPressのAMIがnginxを利用していたのでそれ用の設定。

とりあえずちょっと調べたところによると既にWordPressにはエラーページが用意されているみたい。
https://xxxxxxxxx/?error=404
こんな感じでアクセスするとエラーページが表示される。
でも今、適当なURLでアクセスするとnginx側の404ページが表示される。

スクリーンショット 2020-01-12 12.12.27.png
なので、nginxで404を検知したらWordPressの404ページにリダイレクトする作戦でいく。

サーバー側の設定

設定はすごく簡単。

# error_page....の行を追加
$ sudo vi /etc/nginx/conf.d/wordpres.conf
_/_/_/_/_/_/_/_/_/_/_/_/_/_/
server {
  listen 80;
  server_name olafblog.org;
  error_page 403 404 500 503 =404 /?error=404;

  location / {
    if ($http_x_forwarded_proto = 'http'){
      return 301 https://$host$request_uri;
_/_/_/_/_/_/_/_/_/_/_/_/_/_/

# 再起動
$ sudo nginx -s reload

はい、完了。適当なURLでアクセスしてみる。
スクリーンショット 2020-01-12 12.20.58.png

おk。うまくできた。お疲れ様でした。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2