0

I have multi sites in my web root (/var/www), for example site1, site2, etc. and I configured Nginx as below:

## PHP-FPM Servers ##
upstream localhost-php-fpm {
    server unix:/var/run/php/php7.3-fpm.sock;
}

server {

    server_name localhost;
    
    listen 80;
    
    root /var/www;
    index index.php index.html index.htm;
    
    location /site1/web {
        try_files $uri $uri/ /site1/web/index.php?$args;
    }
    
    location /site2/web {
        try_files $uri $uri/ /site2/web/index.php?$args;
    }
    
    # pass to php-fpm
    location ~ \.php(?:$|/) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass localhost-php-fpm;
        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        include fastcgi_params;
        
        fastcgi_connect_timeout 600;
        fastcgi_send_timeout 600;
        fastcgi_read_timeout 15000;         
    }

}

When I request for root of a site for example http://localhost/site1/web, a download window opens to download index.php. But When I request for some path http://localhost/site1/web/dashboard every thing works fine.

M Sh
  • 1
  • 1

1 Answers1

0

You need to add the try_files directive to your last location block.

Ricaz
  • 11
  • 1
  • Hello @Ricaz, can you explain more? Which directive and how should try_files be? – M Sh Aug 28 '20 at 05:25
  • I add `try_files $uri $uri/ /index.php?$args;` to `location ~ \.php(?:$|/) {` block, but it doesn't work. `index.php` of every site is in `web` folder of that site. – M Sh Aug 28 '20 at 05:34