2011-03-29 107 views
4

我有一個靜態文件index.html。我如何配置nginx從域上的每個路徑提供它?如何使用nginx將許多URL映射到單個文件?

URL | file 
    ----------------- 
    / | index.html 
    /foo | index.html 
    /bar | index.html 
    /baz | index.html 

本質上,我想要一個通配符匹配。

(我知道這將是一個不尋常的設置。)

回答

2

這是你在找什麼?

rewrite ^(.*)$ index.html

+1

你能提供上下文嗎?這應該在配置文件中插入哪裏? – davidchambers 2011-03-30 01:30:44

+2

最後我使用了類似於你的建議的方法:'重寫^。* $ /index.html最後;'(在'server {...}'塊內)。 – davidchambers 2011-03-30 17:16:16

+0

啊yep - 很酷,是的,我遺漏了'server {}'位。 – jeffff 2011-03-30 19:50:58

3

我面臨同樣的問題而回,似乎記得做線沿線的東西:

server { 
    server_name example.com www.example.com; 
    root /var/www/vhosts/example.com; 
    location/{ 
     try_files index.html =404; 
    } 
} 

如果你不介意返回錯誤代碼(例如你下來進行維護),你也可以這樣做:

server { 
    server_name example.com www.example.com; 
    root /var/www/vhosts/example.com; 
    location/{ 
     error 503 index.html; 
     return 503; 
    } 
} 
相關問題