[英]How to serve different url with one file in nginx
I use docker container to serve an html and some other files. 我使用docker容器来提供html和其他文件。 there is no back-end website. 没有后端网站。 I just server some static files. 我只是服务器一些静态文件。
I need to point some different url to one folder. 我需要将一些不同的URL指向一个文件夹。
I have one index.html file in /usr/share/nginx/html. 我在/ usr / share / nginx / html中有一个index.html文件。
I want to point all ulr like: 我想指出所有ulr:
/ , /a , /a/b/c , /a/
to the same: 一样:
/usr/share/nginx/html/index.html file.
my nginx config is as below : 我的nginx配置如下:
server {
listen 80;
location /lalala/ {
proxy_pass http://lalalalalala/;
}
location /proxy/bebebebe/ {
proxy_pass https://www.bebebebe.com/;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
I try to use alias like this: 我尝试使用这样的别名:
location / {
root /usr/share/nginx/html;
index index.html index.htm;
alias /a /usr/share/nginx/html
alias /b /usr/share/nginx/html
alias /a/b/c /usr/share/nginx/html
}
But it's not work. 但这是行不通的。
You can use try_files
to look for a specific file and return index.html
if that file is not found. 您可以使用try_files
查找特定文件,如果找不到该文件,则返回index.html
。
For example: 例如:
location / {
root /usr/share/nginx/html;
try_files $uri /index.html;
}
See this document for details. 有关详细信息,请参见此文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.