Help us understand the problem. What is going on with this article?

Laravel5.7をサブディレクトリで動かす

More than 1 year has passed since last update.

概要

ローカルで作成したLaravelアプリを公開サーバーのサブディレクトリに設置して動かそうとしたところ、うまくいかずはまってしまいました。
ひとまず、動作するようになったため、設定内容を共有いたします。

サーバー環境

  • centos 6.9
  • nginx 1.10
  • laravel 5.7

nginxに設定しているドキュメントルートは
/usr/share/nginx/html/

laravelアプリ配置先は
/usr/share/nginx/html/apps/kus/

アプリのURLは
https://www.mydomain.com/kus/
となります。

設定内容

いろいろな方の設定例をつぎはぎして作成したため、ベストプラクティスにはなりえないかと思いますが、ご了承ください。
設定ファイル名がkus.confとなっていますが、kusはアプリの名前です。
下記設定ファイルはnginxの別設定ファイルからincludeされることを前提に記述されています。
nginx設定ファイルのlocationディレクティブが指定可能な箇所でincludeして下さい。

kus.conf
location /kus {
    alias /usr/share/nginx/html/apps/kus/public;
    try_files $uri $uri/ @nested;

    location ~ \.php$ {
        include                  fastcgi_params;
        fastcgi_param            SCRIPT_FILENAME /usr/share/nginx/html/apps/kus/public/index.php;
        fastcgi_param            PATHINFO        $fastcgi_path_info;
        fastcgi_param            PATH_TRANSLATED /usr/share/nginx/html/apps/kus/public/$fastcgi_path_info;
        fastcgi_split_path_info  ^(.+?.php)(/.+)$;
        fastcgi_pass            127.0.0.1:9000;
        fastcgi_index index.php;

    }
}

location @nested {
    rewrite /kus/(.*)$ /kus/index.php?/$1 last;
}

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away