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

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

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

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

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

1回答

418閲覧

Nginxのディレクティブ設定について

Nanohana

総合スコア123

nginx

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

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

0グッド

0クリップ

投稿2017/08/19 04:15

編集2022/01/12 10:55

Nginxを使っているサーバーで以下のような運用をしたいと思います。

http://xxx.net/ →Wordpressを使用
http://xxx.net/topics/ →Wordpressを使用
http://xxx.net/topics/api/** →cakephpを使用
http://xxx.net/informations/ →Cakephpを使用

cakephpのルートディレクトリは
/var/www/html/xxx/app/webroot にあり、
/var/www/html/xxx/app/Controller/TopicsController.php にコントローラーはあるというような構成になっています

現状の状況は以下の通りです。
WordPressは現状xxx.netで動いています。
CakePHPは現状yyy.net(別ドメイン)で動いています。(/var/www/html/xxx/app/webroot がルートディレクトリ)。
yyy.net/topics/api/** は現状でも見ることができるのですが、
xxx.net/topics/api/** でもアクセスできるようにしたいと考えています。

〜なぜこの処置をするのか〜

現状、yyy.netとxxx.netで運営していてyyy.netではcakephp、
xxx.netではwordpressを使っています。

最終的に
http://yyy.net/ →Wordpressを使用
http://yyy.net/topics/ →Wordpressを使用
http://yyy.net/topics/api/** →cakephpを使用
http://yyy.net/informations/ →Cakephpを使用
という形にしたいため、wordpressが動いているxxx.netでNginxの設定をいじって

http://xxx.net/ →Wordpressを使用
http://xxx.net/topics/ →Wordpressを使用
http://xxx.net/topics/api/** →cakephpを使用
http://xxx.net/informations/ →Cakephpを使用
という構成で検証をして、問題なければyyy.netで同じような設定を導入しようと思っています。

以下の設定でうまくいかないのですが、どのように設定すれば良いのでしょうか...

lang

1server { 2 listen 80; 3 server_name xxx.net; 4 access_log /home/kusanagi/xxx/log/nginx/access.log main; 5 error_log /home/kusanagi/xxx/log/nginx/error.log warn; 6 charset UTF-8; 7 client_max_body_size 16M; 8 root /home/kusanagi/xxx/DocumentRoot; 9 index index.php index.html index.htm; 10 11location /topics/article{ 12root /var/www/html/xxx/app/webroot; 13index index.php index.html; 14# try_files /topics/$1 /sample/$1/ /topics/index.php?$1&$args; 15#try_files $uri $uri?$args $uri/ /index.php?$uri&$args /index.php?$args; 16fastcgi_pass 127.0.0.1:9000; 17fastcgi_index index.php; 18fastcgi_param SCRIPT_FILENAME /var/www/html/xxx/app/webroot/$fastcgi_scr ipt_name; 19try_files /topics/$1 /topics/$1/ /subdir/index.php?topics&$1&$args; 20fastcgi_param PATH_INFO $fastcgi_path_info; 21include fastcgi_params; 22} 23 24 25 26location /informations { 27 root /var/www/html/xxx/app/webroot; 28 index index.php index.html; 29# try_files /topics/$1 /sample/$1/ /topics/index.php?$1&$args; 30#try_files $uri $uri?$args $uri/ /index.php?$uri&$args /index.php?$args; 31fastcgi_pass 127.0.0.1:9000; 32fastcgi_index index.php; 33fastcgi_param SCRIPT_FILENAME /var/www/html/xxx/app/webroot/$fastcgi_script_name; 34 try_files /informations/$1 /informations/$1/ /subdir/index.php?informations&$1&$args; 35 36include fastcgi_params; 37} 38 39 40 location / { 41 try_files $uri $uri/ /index.php?$args; 42 } 43 44 location = /favicon.ico { 45 log_not_found off; 46 access_log off; 47 } 48 49 location ~* /\. { 50 deny all; 51 } 52 location ~* /(?:uploads|files)/.*\.php$ { 53 deny all; 54 } 55 56 location ~ [^/]\.php(/|$) { 57 58 fastcgi_split_path_info ^(.+?\.php)(/.*)$; 59 if (!-f $document_root$fastcgi_script_name) { 60 return 404; 61 } 62 fastcgi_pass 127.0.0.1:9000; 63 fastcgi_index index.php; 64 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 65 include fastcgi_params; 66 fastcgi_buffers 256 128k; 67 fastcgi_buffer_size 128k; 68 fastcgi_intercept_errors on; 69 fastcgi_read_timeout 120s; 70 71 set $do_not_cache 1; ## page cache 72 set $device "pc"; 73 74 if ($request_method = POST) { 75 set $do_not_cache 1; 76 } 77 78 if ($query_string != "") { 79 set $do_not_cache 1; 80 } 81 82 if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { 83 set $do_not_cache 1; 84 } 85 86 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)") { 87 set $do_not_cache 1; 88 } 89 90 if ($http_user_agent ~* " Android |\(iPad|Android; Tablet; .+Firefox") { 91 set $device "tablet"; 92 } 93 94 if ($http_user_agent ~* " Android .+ Mobile |\(iPhone|\(iPod|IEMobile|Android; Mobile; .+Firefox|Windows Phone") { 95 set $device "smart"; 96 } 97 98 fastcgi_cache wpcache; 99 fastcgi_cache_key "$device:$request_method:$scheme://$host$request_uri"; 100 fastcgi_cache_valid 200 10m; 101 fastcgi_no_cache $do_not_cache; 102 fastcgi_cache_bypass $do_not_cache; 103 104 add_header X-F-Cache $upstream_cache_status; 105 add_header X-Signature KUSANAGI; 106 107 } 108 109}

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

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

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

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

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

guest

回答1

0

うまくいかないとはどのような状況ですか。

  1. WordPress だけが動かない
  2. CakePHP だけが動かない
  3. WordPress と CakePHP の両方が動かない
  4. Nginx が起動できない
  5. Nginx は起動するがエラーが表示される

実行はしていないので推測ですが、いずれも PATH_INFO が渡っていないので設定して試してみてください。

nginx

1location /topics/api { 2 fastcgi_param PATH_INFO $fastcgi_path_info; 3}

P.S. information のスペルが違うので直したほうが良いと思います。

投稿2017/08/19 06:45

chitoku

総合スコア1610

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

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

Nanohana

2017/08/19 07:40

ご質問に基づき質問文を修正しました。 Wordpressは動くか、cakephpが動かず404が出るという状態です。 ただし、cakephpは現用側としてyyy.netで運営しているので、そちらでは正常動作しています。 エラー表示は404です。
chitoku

2017/08/19 09:52

CakePHP のバージョンはいくつでしょう。 あるいは yyy.net では Apache だったりしませんか。
Nanohana

2017/08/19 10:07

両方nginxでcakephpは2.9系です。
chitoku

2017/08/19 17:20

CakePHP のための try_files を次のものに変えてみてください。 try_files $uri $uri/ /index.php?$uri&$args; コメントアウトされている try_files が正しくない理由ですが、Nginx は php-fpm が入る場合 1 回しか試行しないためです。
Nanohana

2017/08/20 09:43

try_files $uri $uri/ /index.php?$uri&$args; と設定するとルートディレクトリの設定が無視されて、 Wordpress内で /topics/api などを探しに行くようになってしまいます。 (そうする前はnginxの404エラーでしたので行き先が変わってしまっているようです。) try_filesにルートディレクトリも記載しなくてはいけないのでしょうか
chitoku

2017/08/21 17:14

CakePHP が動作するようになり、逆に今まで動作していた WordPress が動かなくなるということでしょうか。
Nanohana

2017/08/22 16:02

try_files $uri $uri/ /index.php?$uri&$args; を設定すると、 その設定がされているディレクトリでアクセスすると、Wordpressのシステム上で /topics/api  を探しに行っています。そのディレクティブについて、つまりルートディレクトリの設定が有効にならなくなってるようです。 Wordpressはそのディレクティブでなければ正常動作です。
chitoku

2017/08/23 12:38

location /topics/api { } の中に記述しているってことですよね?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問