How to properly configure alias directive in nginx?

前端 未结 1 1987
我寻月下人不归
我寻月下人不归 2020-12-29 12:49

I have been trying to configure multiple webapp on my nginx webserver but I can\'t get working one Laravel app that requires $document_root set to laravel public folder. I

1条回答
  •  隐瞒了意图╮
    2020-12-29 13:14

    I found the solution. It seems that a wrong request was sent for php files. When alias is used it is recommend to use $request_filename instead of $fastcgi_script_name.

    Here is my location block :

    location /paperwork {
    
          alias /var/www/html/paperwork/frontend/public;
          #try_files $uri $uri/;
          location ~ \.php$ {
              fastcgi_pass unix:/var/run/php5-fpm.sock;
              include fastcgi_params;                       
              fastcgi_param SCRIPT_FILENAME $request_filename;
              #fastcgi_intercept_errors on;
          }
    }
    

    This solved my problem for my 'test.php' file which is now executed while reaching https://IP/paperwork/test.php. So alias is working and php is well executed. I still have a problem when trying to reach 'index.php' (which is my laravel app index). File is found but instead of executing it is downloaded. So when I reach https://IP/paperwork/index.php I get a login file downloaded which is index.php file. I get same behaviour if I try /paperwork/index.php/login or /paperwork/login.

    0 讨论(0)
提交回复
热议问题