我試圖在單頁面應用程序工作 - 我需要重寫所有的URL到index.html,但允許現有的靜態文件(.css和.js)作爲他們通常會在瀏覽器中。Nginx重寫靜態文件到index.html
這是我試圖用它來重新編寫代碼,但它成爲我的靜態文件的重新編寫以及
if (!-e $request_filename)
{
rewrite ^/(.*)$ /?/$1 last;
break;
}
我試圖在單頁面應用程序工作 - 我需要重寫所有的URL到index.html,但允許現有的靜態文件(.css和.js)作爲他們通常會在瀏覽器中。Nginx重寫靜態文件到index.html
這是我試圖用它來重新編寫代碼,但它成爲我的靜態文件的重新編寫以及
if (!-e $request_filename)
{
rewrite ^/(.*)$ /?/$1 last;
break;
}
你實際上並不需要重寫的,在nginx的,只是使用try_files像這樣:
location/{
try_files $uri /index.html;
}
這樣做是對所有網址:
看到http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
這應該工作:
server {
listen 1.2.3.4:80;
server_name domain.eu;
root /usr/local/www/domain.eu/public;
try_files $uri @rewrites;
location @rewrites {
rewrite ^/favicon.ico$ /pictures/favicon.ico last;
rewrite ^ /index.html last;
}
}