请帮我配置nginx:我希望nginx返回index.html
所有网址,例如10.10.256.142/
,10.10.256.142/some_path
和10.10.256.142/other_path/lala
。问题:目前仅为index.html
网址返回10.10.256.142/
。
我当前的设置
listen 80;
server_name 10.10.256.142;
server_name_in_redirect off;
resolver 127.0.0.1;
location / {
error_page 405 =200 $uri;
root /some_path/project_dir;
index index.html index.htm;
}
location /websocket {
# ....
答案 0 :(得分:2)
对我来说,最简单的解决方案是:
root /some_path/project_dir;
location / {
rewrite ^ /index.html break;
}
location /websocket/ {
# ...
}
答案 1 :(得分:2)
只是为了完成上面的答案并返回我必须写的静态资产
root /srv/www/betbull;
location / {
if ($uri !~ (/assets/.*)) { # do not return index.html instead of static assets
rewrite ^ /index.html break;
}
}
更新:
更好的解决方案:
location / {
try_files $uri $uri/ index.html$query_string
}