nginx giving 404 when accessing php from alias directory
- by code90
I am trying to migrate from apache to nginx. The php sites that I am hosting need to access a shared library which turns out to be an alias directory. Below is the configuration I came up with. html files work fine, but php files giving 404. I have read through and tried most (if not all) of the answers to the similar questions with no any success. Any hint on what might be causing the issue in my case?
location /wtlib/ {
alias /var/www/shared/wtlib_4/;
index index.php;
}
location ~ /wtlib/.*\.php$ {
alias /var/www/shared/wtlib_4/;
try_files $uri =404;
if ($fastcgi_script_name ~ /wtlib(/.*\.php)$) {
set $valid_fastcgi_script_name $1;
}
fastcgi_pass 127.0.0.1:9013;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/shared/wtlib_4$valid_fastcgi_script_name;
fastcgi_param REDIRECT_STATUS 200;
include /etc/nginx/fastcgi_params;
}
Thanks all !
Update: Following seems to be working fine:
location /wtlib/ {
alias /usr/share/php/wtlib_4/;
location ~* .*\.php$ {
try_files $uri @php_wtlib;
}
location ~* \.(html|htm|js|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air)$ {
expires 7d;
access_log off;
}
}
location @php_wtlib {
if ($fastcgi_script_name ~ /wtlib(/.*\.php)$) {
set $valid_fastcgi_script_name $1;
}
fastcgi_pass $byr_pass;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/php/wtlib_4$valid_fastcgi_script_name;
fastcgi_param REDIRECT_STATUS 200;
include /etc/nginx/fastcgi_params;
}