server {
listen 8088;
server_name test.example.com;
root /home/www/test_tec.example.com/upload;
index index.html index.php;
access_log log/test_tec_access.log;
error_log log/test_tec_error.log;
location / {
include /home/www/test_tec.example.com/upload/*.conf;
index index.html index.php;
}
location /wiki {
alias /home/www/wiki.example.com/;
index index.html index.php;
}
location ~ \.php {
include ext/php.conf;
include ext/cors.conf;
}
include ext/expired.conf;
}
请教一下nginx配置二级域名问题
之前location /wiki 配置规则用的是 root 通过url访问,总会在root后多加一句/wiki
看了一些教程,说用alias 可以避免这个问题,于是改成图中这样的规则,但是现在访问该二级直接报错
File not found.
error.log
2018/02/02 09:24:47 [error] 13644#0: *20723710 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 49.77.232.248, server: test.example.com, request: "GET /wiki/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "test.example.com:8088"
请问如何解决??
如果某个location里要配置alias指令
请在路径后面加上 /
比如
另外配置请贴文字,要打马赛克用example替换。
基于楼主补充的日志
问题出在
location /wiki/
上这个location使用了alias,但后面还有一个
location ~ \.php
,这样先匹配wiki再匹配\.php
,到\.php
,环境还是server
块的root
指令解决办法:
如果一个location里使用了alias,但又会匹配到其他location,需要把其他location的配置加到这个location里