我在nginx中设置这个别名以正确显示我的网站时遇到了很多麻烦.
我关注的网站应该可以访问,mywebsite.com/mr
并且与位于的网站不同mywebsite.com/
.该网站位于/fullpath
(为简单起见缩短)该网站需要提供三种内容:
/fullpath/index.html
..html
浏览器中显示扩展名)./fullpath
和子目录中.我已经尝试改变比赛的顺序,try_files
并找到了他们都工作的情况,但不是在同一时间:
location /mr {
default_type "text/html";
alias /fullpath;
# with this one 1 and 3 work
# try_files $uri/index.html $uri.html $uri;
# with this one 2 and 3 work
# try_files $uri $uri.html $uri/index.html;
# with this one 1 and 2 work
try_files $uri.html $uri/index.html $uri;
}
Run Code Online (Sandbox Code Playgroud)
当一个人不工作时404.有谁知道我怎么能正确地提供各种文件?
Dan*_*ack 29
显然别名和try_files 不能一起工作.但是,我认为你不需要使用别名.
location /mr {
default_type "text/html";
try_files /fullpath/$uri /fullpath/$uri.html /fullpath/$uri/index.html /fullpath/index.html;
}
Run Code Online (Sandbox Code Playgroud)
哪个会尝试:
我认为root指令确实适用于try文件但无法测试.
server{
location /mr {
root /home/mysite/fullpath;
default_type "text/html";
try_files $uri $uri.html $uri/index.html index.html;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用了@Danack发布的组合,这使我得到了我正在寻找的结果(直接提供html文件):
location /health-check {
default_type "text/html";
alias /path/to/my/file.html;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
30868 次 |
最近记录: |