这里是我的Nginxconfiguration,简而言之:
... server { listen 80; server_name whatever; root /var/www/; location /api/1.0 { ... `proxy_pass http://localhost:8000/; } location /api/2.0 { ... proxy_pass http://localhost:8080/; } location / { root /var/www/static/; default_type text/html; try_files $uri $uri/index.html index.html; } }
如果我现在去localhost ,并追加一个随机的名称,不符合我的静态文件中的任何东西,或任何两个应用程序(例如http://localhost/whatever )中的http://localhost/whatever ,我在我的一个奇怪的错误日志:
打开()“/var/wwwindex.html”失败(2:没有这样的文件或目录),客户端:127.0.0.1,服务器:ec2 -54-234-175-21.compute-1.amazonaws.com,请求:“GET / whatever HTTP / 1.1”,主机:“localhost”
我认为这必须反映出我的理解力不足,因为我真的不知道为什么nginx试图访问“/var/wwwindex.html”。 请注意,我不希望这个请求成功,我只是希望它以我明白的方式失败。 究竟发生了什么? 感谢赞赏,在此先感谢!
你的try_files以index.html结尾,而index.html被附加到root (而忽略root的尾部/ )。 添加一个/它。
try_files $uri $uri/index.html /index.html;