LEMPer icon indicating copy to clipboard operation
LEMPer copied to clipboard

Nginx: improve laravel conf & add sub directory install support

Open joglomedia opened this issue 1 year ago • 0 comments
trafficstars

Add this

# Remove trailing slash to please routing system.
if (!-d $request_filename) {
    rewrite     ^/(.+)/$ /$1 permanent;
}

after / location block


Sub directory install config

    # version 1
    location ^~ /demo1 {
        alias /home/tom/public_html/demos/demo1/public;
        try_files $uri $uri/ @demo1;

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

    location @demo1 {
        rewrite ^/demo1/(.*)$ /demo1/index.php/$1 last; # THIS IS THE IMPORTANT LINE
    }
    # end version 1

    # version 2
    # this is with `ln -s /home/tom/public_html/demos/demo1/public <document root>/demo1`
    location ~ /demo1 {
        try_files /demo1/$uri /demo1/$uri/ /demo1/index.php?q=$uri&$args;
    }
    # end version 2

Ref: https://gist.github.com/tsolar/8d45ed05bcff8eb75404

joglomedia avatar Jun 03 '24 09:06 joglomedia