如何使Nginx使URL不区分大小写

前端之家收集整理的这篇文章主要介绍了如何使Nginx使URL不区分大小写前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用Nginx做一个简单的演示网站,而我只是配置Nginx

  1. server {
  2. listen 80;
  3. server_name www.abc.com;
  4. location / {
  5. index index.html;
  6. root /home/www.abc.com/;
  7. }
  8. }

在我的www.abc.com文件夹中,我有子文件夹Sub,里面有index.html文件.所以当我尝试访问www.abc.com/Sub/index.html,那么它工作正常.如果我访问www.abc.com/sub/index.html,它返回404.

如何在URL中配置Nginx不区分大小写?

最佳答案
  1. server {
  2. # Default,you don't need this!
  3. #listen 80;
  4. server_name www.abc.com;
  5. # Index and root are global configurations for the whole server.
  6. index index.html;
  7. root /home/www.abc.com/;
  8. location / {
  9. location ~* ^/sub/ {
  10. # The tilde and asterisks ensure that this location will
  11. # be matched case insensitive. Nginx does not support
  12. # setting absolutely everything to be case insensitive.
  13. # The reason is easy,it's costly in terms of performance.
  14. }
  15. }
  16. }

猜你在找的Nginx相关文章