本文介绍了如何使用Nginx使URL不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将Nginx用于简单的演示网站,而我只是这样配置Nginx:
I am using Nginx for a simple demo website, and I just configure the Nginx like this:
server {
listen 80;
server_name www.abc.com;
location / {
index index.html;
root /home/www.abc.com/;
}
}
在我的www.abc.com
文件夹中,我有一个名为Sub
的子文件夹,并且里面有index.html
文件.因此,当我尝试访问www.abc.com/Sub/index.html
时,效果很好.如果我访问www.abc.com/sub/index.html
,它将返回404
.
In my www.abc.com
folder, I have sub-folder named Sub
, and inside has index.html
file. So when I try to visit www.abc.com/Sub/index.html
, then it works fine. If I visit www.abc.com/sub/index.html
, it returns 404
.
如何在URL中将Nginx配置为不区分大小写?
How to configure the Nginx to case-insensitive in URL?
推荐答案
server {
# Default, you don't need this!
#listen 80;
server_name www.abc.com;
# Index and root are global configurations for the whole server.
index index.html;
root /home/www.abc.com/;
location / {
location ~* ^/sub/ {
# The tilde and asterisks ensure that this location will
# be matched case insensitive. nginx does not support
# setting absolutely everything to be case insensitive.
# The reason is easy, it's costly in terms of performance.
}
}
}
这篇关于如何使用Nginx使URL不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!