当我访问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进程:
root@h2638935:/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
root@h2638935:/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 :(得分:0)
尝试:
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
获取别名路径名。答案 1 :(得分:0)
永远不要忘记try_files指令的行为:
try_files
指令的最后一个参数导致重新评估当前作用域中的所有location
块(通常为server
)。
/index.php?$query_string;
与/cachet/
前缀不匹配,因此永远不会到达PHP引擎的嵌套位置。