Nginx `location /` 不匹配 `/some_path`
Nginx `location /` does not match `/some_path`
请帮我配置 nginx:我想要 nginx return index.html
用于所有 URL,例如 10.10.256.142/
、10.10.256.142/some_path
和 10.10.256.142/other_path/lala
.问题:目前 returns index.html
仅适用于 10.10.256.142/
URL.
我的当前设置
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 {
# ....
对我来说,最简单的解决方案是:
root /some_path/project_dir;
location / {
rewrite ^ /index.html break;
}
location /websocket/ {
# ...
}
只是为了完成上面的答案和 return 我必须编写的静态资产
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
}
请帮我配置 nginx:我想要 nginx return index.html
用于所有 URL,例如 10.10.256.142/
、10.10.256.142/some_path
和 10.10.256.142/other_path/lala
.问题:目前 returns index.html
仅适用于 10.10.256.142/
URL.
我的当前设置
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 {
# ....
对我来说,最简单的解决方案是:
root /some_path/project_dir;
location / {
rewrite ^ /index.html break;
}
location /websocket/ {
# ...
}
只是为了完成上面的答案和 return 我必须编写的静态资产
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
}