Yii2开启路由美化后无法进行路由解析
报错如下:
2021/03/22 21:22:28 [error] 26856#0: *86 open() "/Users/xueyanxiang/qttwork/adv-satellite-api/web/test/run" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /test/run HTTP/1.1", host: "localhost:1111"
原因:
nginx的路由配置有问题,不能采用默认的样式如下:
location / {
root html;
index index.php index.html index.htm;
}
而应该改为:
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
整体配置:
server {
listen 1111;
server_name localhost;
root /Users/xueyanxiang/qttwork/adv-satellite-api/web;
index index.php
access_log /Users/xueyanxiang/logs/nginx_logs/1111_access.log main;
error_log /Users/xueyanxiang/logs/nginx_logs/1111_error.log;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}