我希望能够使用nginx运行yii2(高级模板)项目。我使用virtualbox和vagrant(ubuntu 16.04,php 5.6)。我的Nginx文件中有以下设置:
我有一个带权限的项目结构,如下所示:
如果我运行b2bfrontend.test,会出现错误- 403 Forbidden。
vhost1.conf
server {
listen *:80;
server_name frontend.test;
client_max_body_size 128m;
root /var/www/frontend/web/;
index index.php;
access_log /var/log/nginx/vhost1.access.log;
error_log /var/log/nginx/vhost1.error.log;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ ^/assets/.*\.php$ {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
location ~* /\. {
deny all;
}
}
我有一个带权限的项目结构,如下所示:
vagrant@machine1]-[/var/www]-[git master]
$ ls -la frontend/
total 68
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 ./
drwxrwxr-x 1 vagrant vagrant 4096 Jul 9 16:14 ../
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 assets/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 bootstrap/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 components/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 config/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 controllers/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 data/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 helpers/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 messages/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 models/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 modules/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 runtime/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 validators/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 views/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 web/
drwxrwxr-x 1 vagrant vagrant 4096 Jul 5 14:27 widgets/
nginx错误日志输出:
2018/07/09 21:42:36 [error] 23865#23865: *1 directory index of "/var/www/frontend/web/" is forbidden, client: 192.168.56.1, server: b2bfrontend.test, request: "GET / HTTP/1.1", host: "b2bfrontend.test"
如果我运行b2bfrontend.test,会出现错误- 403 Forbidden。