我有這樣的nginx的配置:Nginx的前端和後端下URL
server{
listen 80;
server_name hans.site.dev;
location/{
index index.html index.php;
root /var/www/a/public;
}
location /api {
root /var/www/b/public;
index index.php index.html index.htm;
try_files $uri /api/$uri/ /index.php?$query_string;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
其中:
- 答:前端(角)
- B:後端(流明)
以後我想補充
- C:管理員(角)
- d:支持(角)
但即使這樣的配置,當我嘗試訪問hans.site.dev/api/,它會給我此錯誤: 「/ var/www/a /public/index.php」failed(2:No such file or directory),client:192.168.56.1,server:hans.site.dev,request:「 GET/api/HTTP/1.1「,主機:」hans.site.dev「。
爲什麼它是指一個,而不是b?以及如何解決它?
注意,現在你的'/ api'位置查找這樣的文件: '在/ var/WWW/B /公/ api'。在這種情況下,你應該使用'alias'。 http://nginx.org/en/docs/http/ngx_http_core_module.html#alias 所以你會被重定向到'/index.php?$ query_string;' –