根目录 =/srv/myproject/xyz/main/
在“主”文件夹中,我有几个 *.html 文件,我希望它们都指向一个 url 说 /test/
(这与目录结构有很大不同)
这是我非常基本的 nginx 配置
server {
listen 80;
error_log /var/log/testc.error.log;
location /test/ {
root /srv/myproject/xyz/main/;
#alias /srv/myproject/xyz/main/;
default_type "text/html";
try_files $uri.html ;
}
}
如果我使用简单别名
location /test/ {
alias /srv/myproject/xyz/main/;
}
那么它的工作完美,我的意思是我可以通过
http://www.myurl.com/test/firstfile.html
访问这些 html 文件等等但我不想要那个 html 扩展。
我试图遵循这些线程但没有成功
http://forum.nginx.org/read.php?11,201491,201494
How to remove both .php and .html extensions from url using NGINX?
how to serve html files in nginx without showing the extension in this alias setup
最佳答案
尝试这个
location ~ ^/test/(.*)$ {
alias /srv/myproject/xyz/main/;
try_files $1.html =404;
}
关于nginx - 在 Nginx 中提供静态 HTML 文件而不在 url 中扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28175222/