html 如何使用Nginx提交一个没有扩展名的文件?

ia2d9nvy  于 2024-01-04  发布在  Nginx
关注(0)|答案(1)|浏览(266)

我所有的静态HTML文件都没有扩展名,这意味着它们不是index.html,它们只是index。我如何告诉Nginx访问它们并将它们作为HTML文件交付?我有以下配置。

  1. server {
  2. listen 80;
  3. listen [::]:80;
  4. listen 443 ssl;
  5. listen [::]:443 ssl;
  6. include snippets/snakeoil.conf;
  7. root /home/davidgatti/Documents/example.com;
  8. index home
  9. server_name example.loc;
  10. location / {
  11. default_type text/html;
  12. try_files $uri $uri $uri/ =404;
  13. }
  14. }

字符串
现在Nginx发送回一个404

wixjitnu

wixjitnu1#

最后我想明白了:

  • index /home;需要一个斜杠
  • try_files需要$uri.html不知道为什么,但没有它将无法工作。
  1. #
  2. # Server Configuration
  3. #
  4. server {
  5. listen 80;
  6. listen [::]:80;
  7. listen 443 ssl;
  8. listen [::]:443 ssl;
  9. #
  10. # Use the a default SSL for development.
  11. #
  12. include snippets/snakeoil.conf;
  13. #
  14. # Tell which folder to server.
  15. #
  16. root /home/davidgatti/Documents/Retireryte/YOUR_SITE_NAME/_output;
  17. #
  18. # Set the default file.
  19. #
  20. index /home;
  21. #
  22. # Tell Nginx which url is this configuration for.
  23. #
  24. server_name login.example.loc;
  25. #
  26. # Default configuration.
  27. #
  28. location / {
  29. #
  30. # Since we deliver files with no extension, we need to tell
  31. # Nginx what those files are.
  32. #
  33. default_type text/html;
  34. #
  35. # First attempt to serve request as file, then
  36. # as directory, then fall back to displaying a 404.
  37. #
  38. try_files $uri $uri.html $uri/ =404;
  39. }
  40. }

字符串

展开查看全部

相关问题