joglomedia / LEMPer

LEMPer Stack is terminal-based LEMP / LNMP ( Linux, Nginx, MariaDB, PostgreSQL, MongoDB, Redis, Memcache, PHP, Secure FTP ) auto installer and virtual host manager for Debian & Ubuntu cloud or virtual server (vps) and on-premise (bare metal).
https://lemper.cloud/
GNU General Public License v3.0
208 stars 56 forks source link

Nginx: improve laravel conf & add sub directory install support #170

Open joglomedia opened 3 months ago

joglomedia commented 3 months ago

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