我已经创建了一个简单的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;
}
}
Run Code Online (Sandbox Code Playgroud)
所有工作都按预期正常.因为我正在使用Angular UI路由器,所以我想转发所有页面,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;
}
Run Code Online (Sandbox Code Playgroud)
如本答案所述.但根据所有要求,我无法做任何类似工作.
建议将不胜感激.