質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

phpMyAdmin

phpMyAdminはオープンソースで、PHPで書かれたウェブベースのMySQL管理ツールのことです。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

Q&A

解決済

1回答

1618閲覧

NGINXでindex.php無しの正規化をかけるとphpMyAdminログイン画面が表示され続ける

Katsu.Okada

総合スコア15

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

phpMyAdmin

phpMyAdminはオープンソースで、PHPで書かれたウェブベースのMySQL管理ツールのことです。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

0グッド

0クリップ

投稿2021/05/11 06:32

編集2021/05/12 06:45

やりたいこと:
WordPressのページURLをindex.php無しで正規化しつつ
phpMyAdminを使用したい。

現状:
https://www.hoge.com/phpMyAdmin/
でログインしても、ログインIDとパスワード入力画面が出続ける

index.php無しにする正規化の部分(#A)を削除すると
phpMyAdminにはアクセスできるが
WordPressのページURLにindex.phpが表示されてしまう。

環境:
CentOS7 / php7.3 / kusanagi
WordPressはhttps://www.hoge.com/wp/にインストール
phpMyAdminはhttps://www.hoge.com/phpMyAdmin/にインストール

config(抜粋):

ssl.conf

1server { 2 listen 443 ssl http2; 3 server_name hoge.com; 4 ssl_certificate /etc/letsencrypt/live/hoge.com/fullchain.pem; # managed by Certbot 5 ssl_certificate_key /etc/letsencrypt/live/hoge.com/privkey.pem; # managed by Certbot 6 ssl_dhparam /etc/kusanagi.d/ssl/dhparam.key; 7 ssl_session_tickets on; 8 ssl_session_ticket_key /etc/kusanagi.d/ssl_sess_ticket.key; 9 ssl_session_cache shared:SSL:1m; 10 ssl_session_timeout 5m; 11 ssl_protocols TLSv1.2 TLSv1.3; 12 ssl_ciphers "AES128+ECDHE:AES256+ECDHE:AES128+EDH:AES256+EDH:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4!CAMELLIA!AES128-SHA!AES128-SHA256!AES128-GCM-SHA256:!AES256-GCM-SHA384:!AES256-SHA256:!AES256-SHA!AES256-CCM8!AES256-CCM!AES128-CCM!ARIA128-GCM-SHA256!AES128-CCM8!ARIA256-GCM-SHA384"; 13 ssl_prefer_server_ciphers on; 14 access_log /home/kusanagi/aaa/log/nginx/ssl_access.log main; 15 error_log /home/kusanagi/aaa/log/nginx/ssl_error.log warn; 16 17 charset UTF-8; 18 client_max_body_size 50M; 19 root /home/kusanagi/aaa/DocumentRoot; 20 index index.php index.html index.htm; 21 22 location = /50x.html { 23 return 403; 24 } 25 26 rewrite /wp-admin$ $scheme://$host$uri/ permanent; 27 28 location / { 29 try_files $uri $uri/ /index.php?$args; 30 31# B-start index.phpの内容がダウンロードされる 32 location ~ .php(.*)$ { 33 if ($request_uri ~* "^(.*/)index.php(.*)$") { 34 return 301 $1$2; 35 } 36 } 37# B-end 38 } 39 40 location = /favicon.ico { 41 log_not_found off; 42 access_log off; 43 } 44 45 location ~* /.well-known { 46 allow all; 47 } 48 49 location /phpMyAdmin/ { 50 # Outer Word Press Files 51 root /home/kusanagi/aaa/DocumentRoot; 52 index index.php index.html index.htm; 53 } 54 55 location ~* /. { 56 deny all; 57 } 58 59 location ~* /(?:uploads|files)/.*.php$ { 60 deny all; 61 } 62 63 location ~* .(jpg|jpeg|gif|png|css|js|swf|ico|pdf|svg|eot|ttf|woff)$ { 64 expires 60d; 65 access_log off; 66 } 67 68# A-start 69 #if ($request_uri ~* "^(.*/)index.php(.*)$") { 70 # return 301 $1$2; 71 #} 72# A-end 73 74 location ~* /wp-login.php|/wp-admin/((?!(admin-ajax.php|images/)).)*$ { 75 satisfy any; 76 allow 0.0.0.0/0; 77 allow 127.0.0.1; 78 deny all; 79 auth_basic "basic authentication"; 80 auth_basic_user_file "/home/kusanagi/.htpasswd"; 81 location ~ [^/].php(/|$) { 82 fastcgi_split_path_info ^(.+?.php)(/.*)$; 83 if (!-f $document_root$fastcgi_script_name) { 84 return 404; 85 } 86 fastcgi_pass 127.0.0.1:9000; 87 fastcgi_index index.php; 88 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 89 include fastcgi_params; 90 fastcgi_buffers 256 128k; 91 fastcgi_buffer_size 128k; 92 fastcgi_intercept_errors on; 93 fastcgi_read_timeout 120s; 94 } 95 include conf.d/security.conf; 96 } 97 98 location ~ [^/].php(/|$) { 99 fastcgi_split_path_info ^(.+?.php)(/.*)$; 100 if (!-f $document_root$fastcgi_script_name) { 101 return 404; 102 } 103 fastcgi_pass 127.0.0.1:9000; 104 fastcgi_index index.php; 105 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 106 include fastcgi_params; 107 fastcgi_buffers 256 128k; 108 fastcgi_buffer_size 128k; 109 fastcgi_intercept_errors on; 110 fastcgi_read_timeout 120s; 111 112 set $do_not_cache 1; ## page cache 113 set $device "pc"; 114 115 if ($request_method = POST) { 116 set $do_not_cache 1; 117 } 118 119 if ($query_string != "") { 120 set $do_not_cache 1; 121 } 122 123 if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { 124 set $do_not_cache 1; 125 } 126 127 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)") { 128 set $do_not_cache 1; 129 } 130 131 if ($http_user_agent ~* " Android |(iPad|Android; Tablet; .+Firefox") { 132 set $device "tablet"; 133 } 134 135 if ($http_user_agent ~* "Android .+ Mobile|(iPhone|(iPod|IEMobile|Android; Mobile; .+Firefox|Windows Phone") { 136 set $device "smart"; 137 } 138 139 fastcgi_cache wpcache; 140 fastcgi_cache_key "$device:$request_method:$scheme://$host$request_uri"; 141 fastcgi_cache_valid 200 10m; 142 fastcgi_no_cache $do_not_cache; 143 fastcgi_cache_bypass $do_not_cache; 144 145 add_header X-F-Cache $upstream_cache_status; 146 add_header X-Signature KUSANAGI; 147 include conf.d/security.conf; 148 } 149 150 location ~ /fcache-purge/([^/]+)(/.*) { 151 allow 127.0.0.1; 152 deny all; 153 fastcgi_cache_purge wpcache "$1:GET:$scheme://$host$2"; 154 } 155 156 # WebP Express rules 157 # -------------------- 158 location ~* /wp/wp-content/.*.(png|jpe?g)$ { 159 add_header Vary Accept; 160 expires 365d; 161 if ($http_accept !~* "webp"){ 162 break; 163 } 164 try_files 165 /wp/wp-content/webp-express/webp-images/doc-root/$uri.webp 166 $uri.webp 167 /wp/wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=wp-content 168 ; 169 } 170 171 # Route requests for non-existing webps to the converter 172 location ~* /wp/wp-content/.*.(png|jpe?g).webp$ { 173 try_files 174 $uri 175 /wp/wp-content/plugins/webp-express/wod/webp-realizer.php?wp-content=wp-content 176 ; 177 } 178 # ------------------- (WebP Express rules ends here) 179 180 # WebP extra folder rules 181 # ------------------------- 182 location ~* /images/.*.(png|jpe?g)$ { 183 add_header Vary Accept; 184 try_files $uri$webp_suffix $uri =404; 185 } 186 location ~* /AAA/.*.(png|jpe?g)$ { 187 add_header Vary Accept; 188 try_files $uri$webp_suffix $uri =404; 189 } 190 location ~* /common/images/.*.(png|jpe?g)$ { 191 add_header Vary Accept; 192 try_files $uri$webp_suffix $uri =404; 193 } 194}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

K_3578

2021/05/11 07:42

ごきNGINXで ←ごき?
Katsu.Okada

2021/05/11 07:45

ご指摘ありがとうございます。修正しました
guest

回答1

0

ベストアンサー

WordPress, phpMyAdmin の location を完全に分けて、WordPress の location だけでリダイレクトを設定するといいと思います。

(設定例) location / { try_files $uri $uri/ /index.php?$args; location ~ .php(.*)$ { ## fastcgi_pass など php-fpm への接続設定 if ($request_uri ~* "^(.*/)index.php(.*)$") { return 301 $1$2; } } } location /phpMyAdmin/ { root /home/kusanagi/aaa/DocumentRoot; index index.php index.html index.htm; location ~ .php(.*)$ { ## fastcgi_pass など php-fpm への接続設定 ## リダイレクト設定なし } }

(2021/05/12 17:31) 追記

location 設定が多いですね。
WordPress, phpMyAdmin で location を分けるのはやめて、否定先読みで「/phpMyAdmin 以外だったら」という条件を付け加えるといいのではないでしょうか。

if ($request_uri ~* "^(?!/phpMyAdmin)(.*/)index.php(.*)$") { return 301 $1$2; }

ただ、WordPress 用の設定が phpMyAdmin に悪影響を及ぼす可能性を考えると、バーチャルホストで分けてしまった方がいいかもしれません。

投稿2021/05/12 01:33

編集2021/05/12 08:31
TaichiYanagiya

総合スコア12146

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Katsu.Okada

2021/05/12 06:34

回答ありがとうございます。 分けてみましたところ index.phpの内容がダウンロードされてページ遷移しなくなりました。 挿入した場所が悪かったのかもしれません。 configの抜粋の仕方が悪かったかもしれませんので内容をフルバージョンで書き出してみますので 確認頂けますでしょうか
Katsu.Okada

2021/05/12 09:14

ご確認ありがとうございます。 希望通りの動作が得られました。 ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問