Joh*_*n S 1 amazon nginx angularjs
我有一个我只想在 HTTPS 中运行的服务器。我在 Amazon AMI 上运行 Node 和 Nginx。
要重定向到 HTTPS,我只需将其放在我的 nginx.conf 文件中:
server {
listen 80;
server_name my_server;
return 301 https://$server_name$request_uri;
}
Run Code Online (Sandbox Code Playgroud)
然后配置 SSL。但是,当诸如此类的 Angular urlhttp://www.mypage.com/#/whatever进来时,所产生的重定向https://www.mypage.com/没有重要的 Angular 语法。
如何使它适用于 Angular 哈希标签语法?Nginx 版本是 1.6.2。
谢谢
这不可能。我不打算谈论重定向到不同协议的 nginx 最佳方法。
问题是哈希永远不会发送到服务器。
我知道的每个浏览器都会忽略 URL 中的哈希部分。
因此,例如,如果您将此 URL 发送到示例服务器:
http://localhost/6/?e#hash_here
Run Code Online (Sandbox Code Playgroud)
请求将发送:
http://localhost/6/?e
Run Code Online (Sandbox Code Playgroud)
浏览器只是将其剥离。
从 JS 的角度来看,我会推荐使用一些EventListeneron onhashchange,这样您就可以拦截所有请求并将其存储location.hash在 cookie 中。
现在,当这个请求到达服务器时,您将能够使用 nginx 的$http_cookie(就像angularLocation=#/whatever使用一些正则表达式来查找它是否存在一样)
| 归档时间: |
|
| 查看次数: |
986 次 |
| 最近记录: |