【发布时间】:2016-04-24 05:39:42
【问题描述】:
我正在设置一些 PHP 子域,但我很难让 nginx 做我想做的事。我正在尝试将每个子域发送到应用程序的不同部分。这是我的文件id.conf 的样子(在sites-enabled 目录中):
map $http_host $app {
'api.id.dev' 'api/public';
'www.id.dev' 'www/public';
}
server {
set $base /Users/dev/www/id/apps;
server_name ~^(?<subdomain>.+)\.id\.dev$;
index index.html index.htm index.php;
root $base/$app;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
access_log off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APP_ENV local;
}
}
server {
server_name id.dev;
rewrite ^ http://www.id.dev$request_uri permanent;
}
我的/etc/hosts 中有这些子域的正确映射,我在 nginx 错误日志中看到了这个错误:
2016/04/24 00:26:32 [error] 5691#0: *5 directory index of "/Users/dev/www/id/apps//" is forbidden, client: 127.0.0.1, server: ~^(?<subdomain>.+)\.id\.dev$, request: "GET / HTTP/1.1", host: "api.id.dev"
这表明主机在那里,并且正在读取 conf 文件,但似乎没有将 http 主机与正确的目录匹配。 (另外,这些子域的目录有一个index.php 文件)
这里有什么问题?我有另一个配置文件正在做同样的事情,它正在工作。事实上,我可以加载一个单独的选项卡并加载其他网站,但它似乎不适用于这个项目(而且我已经验证了很多次文件路径)
【问题讨论】:
-
是我,还是您错过了没有子域的基本情况;例如
http://id.dev被请求。 -
@BurhanKhalid 这应该在最后由重写处理。我刚刚对其进行了测试,它会正确重定向,但它仍然无法正确映射,因此它还尝试访问无效目录 =/
标签: nginx