嵌套Laravel项目Nginx配置

时间:2014-01-22 18:01:23

标签: php nginx laravel

我们在我们的网站上引入了一个使用Laravel框架的新部分。它位于子目录中,例如/newsection。我应该如何配置nginx.conf而不与我以前的重写规则发生任何冲突。

这是我目前的nginx.conf

    server {
        listen  80;
        server_name  localhost www.website.com;
        root  /home/www/website;
        index  index.html index.php;

        location /newsection/ { 
           rewrite ^/ /newsection/public/index.php last;  
           # this is my attempt at it
        }

         location / {
            try_files $uri $uri/ @rewrite;
         }

         location /php-status {
            fastcgi_pass unix:/var/run/php-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
         }


         location @rewrite {
            rewrite  ^/([\w_-]+)/?$ /index.php?page=$1 last;
            rewrite  ^/([\w_-]+)/([\w_-]+)/?$ /index.php?page=$1&slug=$2 last;
            rewrite  ^/([\w_-]+)/([\w_-]+)/([\w_-]+)/?$ /index.php?page=$1&slug=$2&pagination=$3 last;
          }

        include php.conf;
    }

2 个答案:

答案 0 :(得分:1)

如果它像大多数框架一样工作,我知道工作,这应该工作

location /newsection/ { 
   try_files $uri $uri/ /newsection/public/index.php$request_uri;
}

如果此操作返回404,请尝试删除/newsection

的后备URI中的额外try_files

答案 1 :(得分:0)

尝试使用laravelin子目录

location ^~ /laravel {
alias /var/www/laravel/public;
try_files $uri $uri/ @laravel;

location ~ \.php {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    include /etc/nginx/fastcgi_params;
}
}


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