0

We are introducing a new section on our website which uses the Laravel framework. It is placed in a sub-directory, for example /newsection. How should I configure the nginx.conf without making any conflicts with my previous rewrite rules.

This is my current 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 Answers 2

1

If it works like most frameworks I know work, this should work

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

If this returns 404 try removing the extra /newsection in the fallback URI of the try_files

Sign up to request clarification or add additional context in comments.

1 Comment

I was not patient and decided to go for a subdomain solution. When I find time I will test your answer. Thanks.
0

Try this for laravelin subdirectories

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.