繁体   English   中英

如何在Nginx中使用一个文件提供不同的URL

[英]How to serve different url with one file in nginx

我使用docker容器来提供html和其他文件。 没有后端网站。 我只是服务器一些静态文件。

我需要将一些不同的URL指向一个文件夹。

我在/ usr / share / nginx / html中有一个index.html文件。

我想指出所有ulr:

 / , /a , /a/b/c , /a/ 

一样:

/usr/share/nginx/html/index.html file.

我的nginx配置如下:

server {
    listen       80;

    location /lalala/ {
        proxy_pass http://lalalalalala/;
    }

    location /proxy/bebebebe/ {
        proxy_pass https://www.bebebebe.com/;
    }

    location / {
      root /usr/share/nginx/html;
      index  index.html index.htm;
    }
}

我尝试使用这样的别名:

location / {
  root /usr/share/nginx/html;
  index  index.html index.htm;
  alias /a /usr/share/nginx/html
  alias /b /usr/share/nginx/html      
  alias /a/b/c /usr/share/nginx/html
}

但这是行不通的。

您可以使用try_files查找特定文件,如果找不到该文件,则返回index.html

例如:

location / {
    root /usr/share/nginx/html;
    try_files $uri /index.html;
}

有关详细信息,请参见此文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM