具有虚拟目录的多个Laravel实例

时间:2019-04-16 12:52:19

标签: php laravel nginx

我正在尝试将nginx虚拟主机配置为具有包含静态文件的公共根文件夹和内部具有laravel项目的几个虚拟子文件夹。

我的文件夹结构是:

/var/www/project/html <- where I store static files
/var/www/project/laravel1 <- where I put a laravel project

所以我的目标是拥有这样一个域:

http://example.com <- that serves static files
http://example.com/laravel1 <- that serves laravel project

这是我的nginx虚拟主机配置:

server {
  root /var/www/project/html;
  index index.html index.htm index.php;
  server_name example.com;

  location /laravel1 {
    alias /var/www/project/laravel1/public;
    try_files $uri $uri/ @laravel1;

    location ~ \.php$ {
      try_files $uri /index.php =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_param SCRIPT_FILENAME $request_filename;
      fastcgi_pass unix:/run/php/php7.0-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
    }
  }

  location @laravel1 {
    rewrite /laravel1/(.*)$ /var/www/project/laravel1/public/index.php?$1 last;
  }

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    try_files $uri /index.php =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
  }
}

因此,主文件夹正在提供静态文件,在http://example.com/laravel1可以访问laravel1项目索引,但是如果我尝试访问类似http://example.com/laravel1/page1的laravel路由,nginx返回404页面,并且从调试中我可以说无法处理laravel index.php文件的网址进行处理。

任何人都可以帮忙吗?谢谢

0 个答案:

没有答案