実現したいこと
https://teratail.com/questions/l3g3sgik9io99q
の続きのようなもの。
↑の質問では一番の問題が解決してベストアンサーつけたので改めて。
メインドメインで公開済みのHPのサブディレクトリとして、
WordPressで作ったホームページにアクセスさせたい(URLはそのまま)
前提
ConoHa , Kusanagi9 , nginx
メインドメインのHPはphp、
サブディレクトリに置きたいWordpressはKusanagiManagerで作成済みのプロビジョン
(仮のサブドメインで作成)
作業担当者の知識不足のため、WordPress作成して自前でDB接続というのができないため、
WordPressページを作成するのにKusanagiManagerを使用している。
あるもの
・メインドメインのHP(PHP)
・サブドメインで作ったWordPress(Wordpress,KusanagiManager)
やりたいころ
(メインドメイン)/(サブディレクトリ)/
にアクセスしたらURLは(メインドメイン)/(サブディレクトリ)/のまま
(サブドメイン)のメインページが表示されるようにしたい
試したこと
試したこと1
↑の質問と回答を踏まえ、
php
1 location /(サブディレクトリ名)/ { 2 alias /home/kusanagi/(プロビジョン名)/DocumentRoot/; 3 index index.php; 4 try_files $uri $uri/ /index.php?$args; 5 location ~ \.php$ { 6 rewrite ^/(サブディレクトリ名)/(.*\.php)$ /$1 break; 7 include conf.d/fastcgi.inc; 8 } 9 }
とした。
404や403といったものは返ってこなくなったが、
(サブドメイン)/(サブディレクトリ)/
の中身が返ってくる。(ダミーデータ入れて確認済み)
試したこと2
include conf.d/fastcgi.inc;
をincludeせずに中身をフルパス指定にして書き換えた
php
1 2location ~ \.php$ { 3 fastcgi_split_path_info ^(.+?\.php)(/.*)$; 4 if (!-f /home/kusanagi/(プロビジョン名)/DocumentRoot$fastcgi_script_name) { 5 return 404; 6 } 7 fastcgi_pass (IP):(Port?); 8 fastcgi_index index.php; 9 fastcgi_param SCRIPT_FILENAME /home/kusanagi/(プロビジョン名)/DocumentRoot$fastcgi_script_name; 10 fastcgi_param HTTP_HOST $host; 11 include fastcgi_params; 12 fastcgi_buffers 256 128k; 13 fastcgi_buffer_size 128k; 14 fastcgi_intercept_errors on; 15 fastcgi_read_timeout 120s; 16}
が、動作に変わりはなかった
補足情報(FW/ツールのバージョンなど)
メインドメインのconfファイル全文
php
1server { 2 listen 80; 3 listen [::]:80; 4 5 server_name (メインドメイン) www.(メインドメイン); 6 7 set $do_not_cache 0; ## page cache 8 set $expire_days 90d; 9 10 access_log (略) main; 11 error_log (略) warn; 12 13 14 charset UTF-8; 15 client_max_body_size 600M; 16 root /home/(メインドメインHPのindex.htmlがあるファイルのパス); 17 18 include conf.d/505.inc; 19 include conf.d/favicon.inc; 20 include conf.d/acme.inc; 21 include conf.d/static.inc; 22 23 return 301 https://$host$request_uri; 24 } 25 26 server { 27 include conf.d/ssl_listen.inc; 28 29 server_name (メインドメイン) www.(メインドメイン); 30 31 set $do_not_cache 0; ## page cache 32 set $expire_days 90d; 33 34 ssl_certificate (略); 35 ssl_certificate_key (略); 36 ssl_password_file (略); 37 38 ssl_ct off; 39 ssl_ct_static_scts /etc/opt/kusanagi/nginx; 40 41 include conf.d/ssl.inc; 42 ssl_stapling off; 43 ssl_stapling_verify off; 44 resolver 8.8.4.4 8.8.8.8 valid=300s; 45 resolver_timeout 10s; 46 47 access_log (略) main; 48 error_log (略) warn; 49 50 charset UTF-8; 51 client_max_body_size 600M; 52 root /home/(メインドメインHPのindex.htmlがあるファイルのパス); 53 54 include conf.d/505.inc; 55 include conf.d/favicon.inc; 56 include conf.d/acme.inc; 57 58 location ~ [^/]\.cgi$ { 59 include conf.d/fcgi.inc; 60 } 61 62 location /(サブディレクトリ)/ { 63 alias /home/kusanagi/(プロビジョン名)/DocumentRoot/; 64 index index.php; 65 try_files $uri $uri/ /index.php?$args; 66 location ~ \.php$ { 67 rewrite ^/(サブディレクトリ)/(.*\.php)$ /$1 break; 68 root /home/kusanagi/(プロビジョン名)/DocumentRoot/; 69 fastcgi_split_path_info ^(.+?\.php)(/.*)$; 70 if (!-f $document_root$fastcgi_script_name) { 71 return 404; 72 } 73 fastcgi_pass (IP):(Port?); 74 fastcgi_index index.php; 75 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 76 fastcgi_param HTTP_HOST $host; 77 include fastcgi_params; 78 fastcgi_buffers 256 128k; 79 fastcgi_buffer_size 128k; 80 fastcgi_intercept_errors on; 81 fastcgi_read_timeout 120s; 82 } 83 84 } 85 86 location ~ [^/]\.(php|html)(/|$) { 87 include conf.d/ratelimit.inc; 88 include conf.d/fastcgi.inc; 89 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)") { 90 set $do_not_cache 1; 91 } 92 93 include conf.d/fastcgi_cache.inc; 94 95 add_header X-Signature KUSANAGI; 96 97 } 98 99 include conf.d/static.inc; 100 include conf.d/fcache_purge.inc; 101 102 }
###追記
回答を元にloacationの中にrootを追加したが、動作に変更はなかった。
(ダミーページが返ってきた)
補足にconfファイルの全文を記載した。
質問者はphpに関して知識はない。
(confファイルも元々作成していた別のwordpressプロビジョンからコピペし、意味も分からず改造したもの)

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2025/05/29 10:11
2025/05/29 15:23
2025/05/30 01:40