簡體   English   中英

子文件夾中Laravel的Nginx配置

[英]Nginx configuration for Laravel in subfolder

我已將Laravel 5項目放置在/var/www/my_project/ ,我想通過http://my_domain.com/my_project/ 但是,我不知道如何配置nginx服務器塊。

我想要的是:

  • http://my_domain.com/應該為空。 稍后,另一個項目將在此處可見。
  • http://my_domain.com/my_project/應該是我現在要添加的項目。

請注意,Laravel公用文件夾位於/var/www/my_project/public

這是我的nginx配置(位於/etc/nginx/sites-enabled/ ):

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/my_project/public;
    index index.php index.html index.htm;

    server_name my_ip;

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
            try_files $uri /index.php =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}

實現所需配置的最佳方法是什么?

如果您想將laravel項目放在具有ngnix-ubuntu 16-php.7.2的服務器上的subfolder ,那么這里是update ngnix config:

1)您的嵌套(子文件夾)不在主文件夾內

/var/www/main:
/var/www/nested:

然后您的配置:

location /nested {

        alias /var/www/nested/public;

        try_files $uri $uri/ @nested;

               location ~ \.php$ {
                        include fastcgi_params;
                        fastcgi_param SCRIPT_FILENAME $request_filename;
                        fastcgi_pass   unix:/run/php/php7.2-fpm.sock;

                                }
   }

location @nested {
        rewrite /nested/(.*)$ /nested/index.php?/$1 last;
}

2)您的main內部的laravel-test文件夾(子文件夾):

/var/www/main:
/var/www/main/nested:

然后您的配置:

location /laravel-test {

    alias /var/www/main/laravel-test/public;

    try_files $uri $uri/ @laravelTest;

           location ~ \.php$ {
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $request_filename;
                    fastcgi_pass   unix:/run/php/php7.2-fpm.sock;

                            }


  }

location @laravelTest {
        rewrite /laravel-test/(.*)$ /laravel-test/index.php?/$1 last;
}

這對我有用。 和其他答案沒有被喚醒

location /rmbdatamis/ {
    root            /home/baiduwork/rmb-odp/webroot;
    index index.php;
    include     fastcgi.conf;
    fastcgi_pass $php_upstream;
    if (!-e $request_filename){
        rewrite ^/rmbdatamis/(.*) /rmbdatamis/index.php?/$1 last;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM