33
43

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.

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

Last updated at Posted at 2016-07-25

概要

Apache

/etc/httpd/conf.d/laravel.conf

# いつもどおりのVirtualHost 
<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    DocumentRoot /www/docs/example.com
    ServerName example.com
    ErrorLog logs/example.com-error_log
    CustomLog logs/example.com-access_log common
+   #Aliasを設定する
+   Alias /laravel-twilio "/var/www/laravel/public"
#</VirtualHost>
/var/www/laravel/public/.htaccess
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
+   #サブディレクトリを指定
-   RewriteRule ^(.*)/$ /$1 [L,R=301]
+   RewriteRule ^(.*)/$ /laravel-twilio/$1 [L,R=301]
+   RewriteBase /laravel-twilio

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

nginx

/etc/nginx/conf.d/laravel.conf
# 前略
+    location ^~ /laravel {
+        alias /var/www/laravel/public;
+        try_files $uri $uri/ @laravel01;
+        index index.php index.html index.htm;
+
+        location ~ \.php$ {
+            fastcgi_split_path_info ^(.+\.php)(/.+)$;
+            fastcgi_pass unix:/var/run/php-fpm.sock;
+            include fastcgi_params;
+            fastcgi_param SCRIPT_FILENAME /var/www/laravel/public/index.php;
+        }
+    }
+    
+    location @laravel01 {
+        rewrite /laravel/(.*)$ /laravel/index.php?/$1 last;
+    }
# 後略

あとがき

nginxのfastcgi_param SCRIPT_FILENAMEのところをもう少しスタイリッシュに書きたい。

33
43
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
33
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?