1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel@nginxをシンボリックリンク貼りつつサブディレクトリで動かす

Last updated at Posted at 2018-04-10

環境等

試したのはLaravel5.6、nginx1.12
(CentOS7,PHP7.2)

サブディレクトリで動かすのには、多分以下の感じで書けば動くっぽいが、いっぱい書きたくないなー、もっとスマートに書けないのか?というさぼりの気持ちで。
https://qiita.com/saba1024/items/2d50fb8284d699924360

ディレクトリ構成

メインの処理は/var/www/htmlに置くけど、piyo以下を/home/moge/piyopiyoにあるlaravelを使いたいという場合

/var/www/html/
  ├index.html
  ├hoge/
  ├fuga/
  │  └index.html
  └piyo -> /home/moge/piyopiyo/public(シンボリックリンク)

/home/moge/piyopiyo/
  ├public
  │  └index.php
  ├app
  ├config
  ....

index.phpから__DIR__とかで上位ディレクトリのファイルを参照しますが、本来の/home/moge/piyopiyo/の方に基づいたパスで動きます。

nginxのconfを修正

/etc/nginx/conf.d/XXXX.confに記載
追加部分は以下

        location /piyo/ {
            try_files /piyo/$uri /piyo/$uri/ /piyo/index.php?q=$uri&$args;
        }

全体だとこんな感じ

server {
        listen  80;

        server_name miyawa-tarou.com
        root   /var/www/html;
        index  index.html index.php;

        access_log  /var/log/nginx/access.log main;
        error_log   /var/log/nginx/error.log;

        location /piyo/ {
            try_files /piyo/$uri /piyo/$uri/ /piyo/index.php?q=$uri&$args;
        }

        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php-fpm/www.sock;
            include     fastcgi_params;
            fastcgi_index   index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
}
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?