pri*_*ing 143 javascript history nginx
使用nginx,我想保留url,但无论如何都会加载相同的页面.我将使用url History.getState()
来在我的javascript应用程序中路由请求.看起来这应该是一件简单的事情吗?
location / {
rewrite (.*) base.html break;
}
Run Code Online (Sandbox Code Playgroud)
工作,但重定向网址?我仍然需要网址,我只想总是使用相同的页面.
Ale*_*sky 180
我想这会为你做到:
location / {
try_files /base.html =404;
}
Run Code Online (Sandbox Code Playgroud)
Kev*_*ard 26
使用刚刚try_files
对我不起作用 - 它导致我的日志中的重写或内部重定向周期错误.
Nginx文档有一些额外的细节:
http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
所以我最终使用了以下内容:
root /var/www/mysite;
location / {
try_files $uri /base.html;
}
location = /base.html {
expires 30s;
}
Run Code Online (Sandbox Code Playgroud)
kol*_*ack 17
你的原始重写应该几乎可以工作.我不确定它为什么会重定向,但我认为你真正想要的只是
rewrite ^ /base.html break;
Run Code Online (Sandbox Code Playgroud)
您应该能够将其放在一个位置或直接放在服务器中.
Mar*_*ian 11
这对我有用:
location / {
alias /path/to/my/indexfile/;
try_files $uri /index.html;
}
Run Code Online (Sandbox Code Playgroud)
这使我能够为javascript单页应用创建一个包罗万象的URL.npm run build
如果它们位于同一目录中,将找到所有静态文件,如css,fonts和javascript index.html
.
如果静态文件在另一个目录中,由于某种原因,您还需要以下内容:
# Static pages generated by "npm run build"
location ~ ^/css/|^/fonts/|^/semantic/|^/static/ {
alias /path/to/my/staticfiles/;
}
Run Code Online (Sandbox Code Playgroud)
正确的方法是:
location / {
rewrite (.*) base.html last;
}
Run Code Online (Sandbox Code Playgroud)
使用last
将使nginx location
根据重写结果找到一个新的合适块.
try_files
对于这个问题,这也是一种非常有效的方法.
归档时间: |
|
查看次数: |
94130 次 |
最近记录: |