簡體   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