Nginx没有提供正确的资源
我的用例非常简单:Nginx没有提供正确的资源,nginx,Nginx,我的用例非常简单: /var/www ├── public/ │ └── index.html └── app/ ├── css/ ├── js/ └── index.html 我想将public/index.html作为任何不指向app/(.*)的请求的后备登录页,并在访问mydomain.local/app时提供app/的内容 这个配置有什么问题 server { listen 80; listen [::]:80; listen 192
/var/www
├── public/
│ └── index.html
└── app/
├── css/
├── js/
└── index.html
我想将public/index.html
作为任何不指向app/(.*)
的请求的后备登录页,并在访问mydomain.local/app
时提供app/
的内容
这个配置有什么问题
server {
listen 80;
listen [::]:80;
listen 192.168.0.200:80;
server_name mydomain.local;
index index.html;
location / {
root /var/www/public/;
}
location /app {
root /var/www/;
}
}
以下是使用try_files指令的方法:
server {
listen 80;
listen [::]:80;
listen 192.168.0.200:80;
server_name mydomain.local;
index index.html;
location / {
root /var/www/public/;
try_files $uri /index.html;
}
location /app {
root /var/www/;
}
}
Nginx将尝试匹配$uri,如果不匹配,它将执行到index.html的内部重定向
来源:try\u files/index.html=404;(如果玩具进入mydomain,你可以将404更改为你想要返回的代码。local/foo/bar nginx将在/var/www/public/foo/bar中搜索,而不仅仅是在/var/www/public/中搜索,然后尝试索引。htmlI抱歉,我不确定我应该把这个放在哪里?在位置/括号内。Pablo在他的回答中这样做了:)谢谢,这很有效。有趣的是,我在某个时候有过这种精确的配置——我认为我的指令是错误的,直到我意识到在为生产构建VueJS应用程序时,默认的公共路径是
'/'
,从而解释了为什么我的获取资源时出错。。。