LoginSignup
4
5

More than 5 years have passed since last update.

NginxでサブディレクトリのPhalconを動かす

Last updated at Posted at 2015-01-03

http://localhost/webapp1http://localhost/webapp2などのアクセスで、サブディレクトリのPhalconを動かす設定例です。

/vagrant/webapp1と/vagrant/webapp2_serverにphalconのプロジェクトがあることを前提。

/vagrant/webapp1
          ├── app
          └── public
              └── index.php

/vagrant/webapp2_server
          ├── app
          └── public
              └── index.php

http://localhost/webapp1なら/vagrant/webapp1/public/index.phpを、
http://localhost/webapp2なら/vagrant/webapp2_server/public/index.phpを実行させます。

phalcon_subdirectory.conf
    # URL1つ目のセグメントとディレクトリ名が一致している場合(汎用)
    if ($request_uri ~ /(?<phalcon_subdirectory>\w+)) {
        set $root_path /vagrant/$phalcon_subdirectory/public;
    }
    # URL1つ目のセグメントとディレクトリ名が一致していない場合(/webapp2をwebapp2_serverに対応)
    if ($request_uri ~ /webapp2) {
        set $root_path /vagrant/webapp2_server/public;
    }

    location ~ ^/(?<phalcon_subdirectory>\w+)/(.+\.php)$ {
        include        fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;

        # http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_split_path_info
        # 1つ目は$fastcgi_script_name、2つ目は$fastcgi_path_infoにセットされる
        fastcgi_split_path_info ^/\w+(/.+\.php)(.*)$;

        fastcgi_param  SCRIPT_FILENAME  $root_path$fastcgi_script_name;

        # アプリ任意のSERVER変数
        fastcgi_param  PHALCON_SUBDIRECTORY $phalcon_subdirectory;
        fastcgi_param  APP_ENV local;
    }


    location ~ ^/\w+(.+)? {

        location ~ ^/\w+/\.ht {
            deny  all;
        }

        alias $root_path$1;

        if (!-f $request_filename) {
            rewrite ^/(\w+)/?(.+)?$ /$1/index.php?_url=/$2 last;
        }
    }
4
5
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
4
5