[Nginx] Laravel URL rewriting invalid Solution Blank pages

When deploying Laravel on Nginx, we found a blank page. Middle solve several problems, then record it.

1, Nginx root directory needs to be configured to public

1
root /data/www/laravel/public; #网站根目录

2, Nginx configuration URL Rewrite Rules

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
location / {
    try_files $uri $uri/ /index.php?$query_string;
    #try_files $uri $uri/ @rewrite;
}
 
# 去除末尾的斜杠,SEO更加友好
if (!-d $request_filename)
{
     rewrite ^/(.+)/$ /$1 permanent;
}
 
# 去除index action
if ($request_uri ~* index/?$)
{
     rewrite ^/(.*)/index/?$ /$1 permanent;
}
 
# 根据laravel规则进行url重写
if (!-e $request_filename)
{
     rewrite ^/(.*)$ /index.php?/$1 last;
     break;
}
 
location ~ \.php$ {
     fastcgi_pass 127.0.0.1:9000;
     fastcgi_index index.php;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     #fastcgi_param PATH_INFO       $fastcgi_script_name;
     include fastcgi_params;
}

3, modify fastcgi_params, the following configuration

1
2
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  PATH_INFO          $fastcgi_script_name;

4, by systemctl status nginx.service see nginx service is normal, if not normal reference to the problem with nginx restart nginx; intermediate encounter these modifications are invalid configure how is the problem, because the other nginx start the process leading to itself the service did not start properly

5, run composer install directory under Laravel

6, to ensure that storage directory exists, and the following directory structure exists and permissions to 777

      • framework
        • cache
          • data
        • sessions
        • views
      • logs

7, make sure .env file exists in the root directory, and properly configured

Also be encountered various problems, Tell me what you wish to configure successfully!

Guess you like

Origin www.cnblogs.com/thspz/p/12047943.html