2017-01-27 5 views
0

Когда я получить доступ к http://my_ip/cachet/ я получаю запрещенную ошибкуместо (псевдоним) блок дает запрещено

location /cachet/ { 
    alias /var/www/cachet/public; 
    try_files $uri $uri/ /index.php?$query_string; 

    location ~ \.php$ { 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
     fastcgi_index index.php; 
     include   fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 

Когда я иду к http://my_ip/cachet/index.php он говорит: «Файл не найден».

Nginx должны быть в состоянии прочитать cachet папку,

drwxr-xr-x 13 www-data www-data 4096 jan 27 01:26 cachet 

Запуск PHP и Nginx процесс:

[email protected]:/var/www# ps aux -P | grep nginx 
root  21623 0.0 0.0 125756 1684 ?  Ss 01:43 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; 
www-data 21624 0.0 0.0 125756 2300 ?  S 01:43 0:00 nginx: worker process 
www-data 21625 0.0 0.0 125756 2992 ?  S 01:43 0:00 nginx: worker process 
root  21636 0.0 0.0 12888 1120 pts/0 S+ 01:50 0:00 grep --color=auto nginx 
[email protected]:/var/www# ps aux -P | grep php 
root  17562 0.0 0.4 280252 19476 ?  Ss jan26 0:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf) 
www-data 17563 0.0 0.6 285472 26408 ?  S jan26 0:00 php-fpm: pool www 
www-data 17564 0.0 0.6 285792 26708 ?  S jan26 0:00 php-fpm: pool www 
root  21638 0.0 0.0 12888 1116 pts/0 S+ 01:50 0:00 grep --color=auto php 

ответ

0

Try:

location ^~ /cachet/ { 
    alias /var/www/cachet/public/; 
    if (!-e $request_filename) { rewrite^/cachet/index.php last; } 

    location ~ \.php$ { 
     if (!-f $request_filename) { return 404; } 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
     include   fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $request_filename; 
    } 
} 
  • Значения местоположения и псевдонима должны либо оба заканчиваются на / или ни в конце, ни в /. См. this document для получения дополнительной информации.
  • Не используйте alias и try_files вместе. См. this long term issue и this caution using if.
  • Используйте $request_filename для получения псевдонимов.
0

Никогда не забывайте поведение директивы try_files: Последние пары из try_files директивы приводит к переоценке ВСЕХ location блоков в текущей области (обычно server).

/index.php?$query_string; не соответствует префиксу /cachet/, поэтому ваше вложенное местоположение для PHP Engine никогда не достигается.