关于php:除root外的Nginx,其他所有重定向到404错误

Nginx except root, all others are redirected to 404 error

我的目标是将两个或多个(将来)Laravel应用程序放在单个域下,并进行别名处理,例如:http:// domain-name / Lara-1和http:// domain-name / Lara-2。
我在使用别名时遇到了麻烦,终于可以通过使用位置来做到这一点,但是现在,除了两个应用程序的根Laravel index.php之外,所有其他uri都会导致404错误。
以下是我的网站可用/默认文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
server {
    listen 80 default_server;
    listen [::]:80 default_server;

   index index.php index.html index.htm;
   try_files $uri $uri/ /index.php?$query_string;

    server_name Domain-IP;

     location ^~ /Lara-1/ {
        alias /var/www/Lara-1/public/;

        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php5.6-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
         }

     location ^~ /Lara-2/ {
     alias /var/www/Lara-2/public/;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php5.6-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    include fastcgi_params;
    }

  location ~ /\\.ht {
            deny all;
    }
 }

在单个应用程序而不是两个应用程序的情况下(即只有Lara-1),当我将根设置为
/ var / www / Lara-1 / public /;一切正常。以上情况仅在应用程序别名的情况下发生。可能是,我可能配置错误。

以下是我的fastcgi_params文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

我是Nginx和Laravel的新手。感谢您的帮助!


让该应用在反复试验和错误之后能够正常工作。以下是我的Nginx默认文件在webroot目录下放置2个Laravel应用后的样子。
碰巧使用Nginx网址重写。希望对您有所帮助!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    index index.php index.html index.htm;

    server_name 172.3.21.1;
    root /var/www/webroot/;

location /projectdev {
        rewrite ^/projectdev/(.*)$ /projectdev/public/index.php?$1 last;
    }      

location /projectqa {
        rewrite ^/projectqa/(.*)$ /projectqa/public/index.php?$1 last;
    }
    error_page 401 403 404 /404.html;

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

     location ~ \\.php$ {    
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;  
    }

    location ~* .(woff|eot|ttf|svg|mp4|webm|jpg|jpeg|png|gif|ico|css|js)$ {
               expires 365d;
    }
    # deny access to .htaccess files, if Apache's document root
   # concurs with nginx's one
   #
   location ~ /\\.ht {
            deny all;
    }
    # Block web attacks
   location ~* (roundcube|webdav|smtp|http\\:|soap|w00tw00t)
    {
    return 444;
    }

    # Protect .ini files
   location ~ /\\.ini
    {
    access_log off;
    log_not_found off;
    deny all;
    }
     location ~ /\\.xml {
            deny all;
    }
}