【发布时间】:2018-11-15 20:33:03
【问题描述】:
我是 Nginx 的新手,我正在尝试从 Apache 导入旧站点。我想摆脱虚拟目录,但不幸的是我做不到。
虚拟目录指向主站点的同一个根。代码中有检测虚拟目录并根据该信息加载数据的逻辑,这就是它存在的原因。
这是我试图开始工作的配置:
server {
listen 80;
large_client_header_buffers 4 32k;
server_name site.domain.com;
access_log /var/log/sites/site.access.log;
error_log /var/log/sites/site.error.log error;
location / {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}
location /sitea {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}
location ~ /\.ht {
deny all;
}
}
php.inc 的内容:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
我已经尝试了谷歌提供的所有方法来让它工作,但无论我做什么,我都会继续收到以下错误:
2018/11/15 20:28:32 [debug] 5056#5056: *1 http script var: "/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "/sitea/index.php" "/var/www/php/site/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "=404" "/var/www/php/site=404"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http finalize request: 404, "/sitea/index.php?requestType=home" a:1, c:1
2018/11/15 20:28:32 [debug] 5056#5056: *1 http special response: 404, "/sitea/index.php?requestType=home"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http set discard body
2018/11/15 20:28:32 [debug] 5056#5056: *1 xslt filter header
2018/11/15 20:28:32 [debug] 5056#5056: *1 HTTP/1.1 404 Not Found
对正确方向的任何帮助将不胜感激。
注意:使用 alias 与 root 也可以做同样的事情
使用别名我得到以下信息:
2018/11/15 20:37:38 [错误] 5189#5189: *1 FastCGI 在标准错误中发送: 从上游读取响应标头时出现“主脚本未知”, 客户端:#.#.#.#,服务器:site.domain.com,请求:“GET /sitea/index.php?requestType=home HTTP/1.1",上游: “fastcgi://unix:/run/php/php7.0-fpm.sock:”,主机:“site.domain.com”
可能的解决方案
我不确定这是否是正确的做法,但它确实有效。
如果我为站点加载的主文件夹中的虚拟目录创建了符号链接。我宁愿在 Nginx 中这样做,但如果我必须走这条路,我会的。想法?
【问题讨论】:
-
URI为
/sitea/index.php的文件在什么位置? -
/var/www/php/site谢谢
标签: nginx