Nginx`position /`与`/ some_path`不匹配

时间:2016-03-11 11:44:42

标签: nginx location

请帮我配置nginx:我希望nginx返回index.html所有网址,例如10.10.256.142/10.10.256.142/some_path10.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 {
    # ....

2 个答案:

答案 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
}