Config nginx for Laravel In a subfolder

后端 未结 7 698
失恋的感觉
失恋的感觉 2020-12-14 18:28

I have and old project that now requires new functionality, I\'m going to use laravel to provide it, everything in working ok in xampp with apache but my server con nginx sh

7条回答
  •  独厮守ぢ
    2020-12-14 18:57

    Well, I found a solution to very easy config and install Laravel in a subdirectory in a nginx server, in the /etc/nginx/sites-available/yourSite config file, add this:

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

    and voila, your routes will work normally how they should.

提交回复
热议问题