Home  >  Article  >  PHP Framework  >  Can laravel be configured to an existing site path in nginx?

Can laravel be configured to an existing site path in nginx?

藏色散人
藏色散人forward
2021-11-24 15:47:472119browse

The following column Laravel Tutorial will introduce to you how to configure laravel in nginx under the path of an existing site. I hope it will be helpful to everyone!

Problem description:

How to configure laravel in nginx to the path of an existing site

The configuration file is as follows, there is already one The site is working. Created a new laravel project, in other path:/var/www/html/laravel.

How to configure to access sms.dev/laravel/path normally?

server{
        listen 80;
        server_name sms.dev;
        index index.php index.html index.htm;
        root /var/www/html/sms;
        location /laravel/ {
            # 这里如何配置呢?
        }
        location ~ .*\.(php|php5)?$
        {
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fcgi.conf;
        }
        
        if (!-e $request_filename) {
                return 404;
        }
}

Solution Method:

location ^~ /app/ {
    alias /var/www/laravel/public/;
    if (!-e $request_filename) { rewrite ^ /app/index.php last; }
    location ~ \.php$ {
        if (!-f $request_filename) { return 404; }
        include snippets/fastcgi-php.conf;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
}

[Related recommendations: The latest five Laravel video tutorials]

The above is the detailed content of Can laravel be configured to an existing site path in nginx?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete