【发布时间】:2016-05-04 10:49:58
【问题描述】:
我已经创建了一个简单的 Nginx 配置文件来像这样为 Angular 提供服务:
server {
listen 80;
listen [::]:80;
root /path/to/apps/myapp/current/dist;
access_log /path/to/apps/myapp/current/log/nginx.access.log;
error_log /path/to/apps/myapp/current/log/nginx.error.log info;
index index.html;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location / {
try_files $uri $uri/ =404;
}
}
一切正常。因为我使用的是Angular UI Router,所以我想将所有页面转发到index.html,这样Angular就会接管(所以对example.com/users/new的请求将由Nginx重定向到index.html,以便Angular UI处理它) 用于页面重新加载、链接等。
我怎样才能做到这一点?
我玩过以下选项:
server {
#implemented by default, change if you need different ip or port
#listen *:80 | *:8000;
server_name test.com;
return 301 $scheme://www.test.com$request_uri;
}
如this 答案中所述。但我无法根据所有请求进行类似的工作。
我们将不胜感激。
【问题讨论】:
标签: javascript angularjs nginx