【问题标题】:Nested Laravel Project Nginx Config嵌套 Laravel 项目 Nginx 配置
【发布时间】:2015-01-06 03:14:18
【问题描述】:

我们将在我们的网站上引入一个使用 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;
    }

【问题讨论】:

    标签: php nginx laravel


    【解决方案1】:

    如果它像我知道的大多数框架一样工作,那么它应该可以工作

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

    如果返回 404,请尝试删除 try_files 的后备 URI 中的额外 /newsection

    【讨论】:

    • 我没有耐心,决定采用子域解决方案。当我有时间时,我会测试你的答案。谢谢。
    【解决方案2】:

    对 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;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-01-19
      • 1970-01-01
      • 2017-07-25
      • 2016-09-24
      • 1970-01-01
      • 1970-01-01
      • 2016-04-22
      • 2014-02-01
      • 2014-09-28
      相关资源
      最近更新 更多