【发布时间】:2014-05-21 18:46:33
【问题描述】:
我有一个位置块,我为它定义了一个不同的别名,我希望它的index.php 文件是来自同一目录的服务器。问题是 Nginx 没有使用别名提供索引文件,而是试图在根目录中找到该文件(并且它不存在)。
配置:
http {
sendfile on;
tcp_nopush on;
keepalive_timeout 15;
upstream php {
server unix:/run/php-fpm.sock;
}
server {
server_name my.domain.com;
root /var/www;
location / {
alias /var/www/site/;
index index.php;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php;
}
location ~ /\.ht {
deny all;
}
}
}
所以根应该指向根内的site/目录(/var/www),但试图提供的文件是/var/www/index.php:
2014/05/21 15:41:19 [error] 9591#0: *190 FastCGI sent in stderr: "Unable to open primary script: /var/www/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: my.domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm.sock:", host: "localhost:666"
相反,我希望从/var/www/index.php 提供文件。
【问题讨论】:
-
别名和root相同的原因是什么?另外,fastcgi_params 里有什么?
-
对不起,它们不一样,我修好了。
fastcgi_params是gist.github.com/ranisalt/b0eb02dc07f8d23649d1 -
location /中的alias是什么原因?alias只是位置的替代品,不是root。 -
很多位置都有不同的根文件夹,我使用别名,因为其中一些与目录不匹配。