Nextcloud在宝塔面板和Nginx环境移除URL中的index.php

前言

搭建Nextcloud云同步项目,项目域名URL中有“index.php”字符,影响URL的美观,从用户体验的角度来看,一个简洁、没有多余字符的URL会显得更专业、更直观。

Nextcloud在宝塔面板和Nginx环境移除URL中的index.php

搜索引擎通常更倾向于简洁、有意义的URL,移除“index.php”可以使网页的URL更符合搜索引擎的喜好,有助于提高网站在搜索结果中的排名。简洁的URL还能减少重复内容的可能性,避免因为URL结构复杂而导致的搜索引擎误判。

Nextcloud在宝塔面板和Nginx环境移除URL中的index.php

操作步骤

一、按照下图在宝塔面板的文件管理功能,找到Nextcloud使用的PHP对应版本配置文件(路径:/www/server/nginx/conf),例如我搭建的Nextcloud使用的PHP版本是8.2,在conf目录里找到enable-php-82.conf,双击此文件。

Nextcloud在宝塔面板和Nginx环境移除URL中的index.php

二、按照下图在配置文件中添加以下代码并保存文件。

  1. fastcgi_param front_controller_active true;

Nextcloud在宝塔面板和Nginx环境移除URL中的index.php

三、在conf目录中双击打开mime.types文件。

Nextcloud在宝塔面板和Nginx环境移除URL中的index.php

四、按照下图添加以下代码并保存文件。

  1. application/javascript mjs;

Nextcloud在宝塔面板和Nginx环境移除URL中的index.php

五、在网站设置的伪静态规则添加以下代码并保存配置。

  1. location ~ ^/.well-known/carddav {
  2. return 301 $scheme://$host/remote.php/dav;
  3. }
  4. location ~ ^/.well-known/caldav {
  5. return 301 $scheme://$host/remote.php/dav;
  6. }
  7. location /.well-known {
  8. rewrite ^/.well-known/webfinger /index.php/.well-known/webfinger last;
  9. rewrite ^/.well-known/nodeinfo /index.php/.well-known/nodeinfo last;
  10. rewrite ^/.well-known/(.*)$ /index.php/.well-known/$1 last;
  11. }
  12. # 处理 Nextcloud 的 ocm-provider 和 ocs-provider
  13. location ^~ /ocm-provider/ {
  14. try_files $uri $uri/ /index.php$request_uri;
  15. }
  16. location ^~ /ocs-provider/ {
  17. try_files $uri $uri/ /index.php$request_uri;
  18. }
  19. #webdav和其他所有请求重定向到index.php上
  20. location / {
  21. rewrite ^ /index.php$uri;
  22. rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
  23. rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
  24. rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
  25. rewrite ^(/core/doc/[^/]+/)$ $1/index.html;
  26. }
  27. #静态资源重定向
  28. location ~* .(?:png|html|ttf|ico|jpg|jpeg)$ {
  29. try_files $uri /index.php$uri$is_args$args;
  30. access_log off;
  31. }
  32. location ~ ^/(?:updater|ocs-provider)(?:$|/) {
  33. try_files $uri/ =404;
  34. index index.php;
  35. }
  36. #安全设置,禁止访问部分敏感内容
  37. location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
  38. deny all;
  39. }
  40. location ~ ^/(?:.|autotest|occ|issue|indie|db_|console) {
  41. deny all;
  42. }
  43. location ~ ^/(data|config|.ht|db_structure.xml|README) {
  44. deny all;
  45. }
  46. location ~ ^/(?:updater|oc[ms]-provider)(?:$|/) {
  47. try_files $uri/ =404;
  48. index index.php;
  49. }
  50. # Adding the cache control header for js, css and map files
  51. # Make sure it is BELOW the PHP block
  52. location ~ .(?:css|js|woff2?|svg|gif|map)$ {
  53. try_files $uri /index.php$request_uri;
  54. add_header Cache-Control "public, max-age=15778463";
  55. add_header Referrer-Policy "no-referrer" always;
  56. add_header X-Content-Type-Options "nosniff" always;
  57. add_header X-Download-Options "noopen" always;
  58. add_header X-Frame-Options "SAMEORIGIN" always;
  59. add_header X-Permitted-Cross-Domain-Policies "none" always;
  60. add_header X-Robots-Tag "none" always;
  61. add_header X-XSS-Protection "1; mode=block" always;
  62. # Optional: Don't log access to assets
  63. access_log off;
  64. }
  65. location ~ .(?:png|html|ttf|ico|jpg|jpeg|bcmap|mp4|webm)$ {
  66. try_files $uri /index.php$request_uri;
  67. # Optional: Don't log access to other assets
  68. access_log off;
  69. }
  70. #mjs报错
  71. location ~* .mjs$ {
  72. types { application/javascript mjs; }
  73. try_files $uri =404;
  74. }
  75. # WASM
  76. location ~* .wasm$ {
  77. types {
  78. application/wasm wasm;
  79. }
  80. add_header Content-Type application/wasm;
  81. expires 7d;
  82. access_log off;
  83. }
  84. # otf
  85. location ~* .otf$ {
  86. types {
  87. application/x-font-otf otf;
  88. font/opentype otf;
  89. }
  90. add_header Access-Control-Allow-Origin *;
  91. expires 30d;
  92. access_log off;
  93. }

六、打开Nextcloud的域名网址或分享链接,URL中没有index.php,这样更美观。

本文发布者:dennyyang,转载请注明出处:https://www.kongyoo.com/website-technology/4194.html

(0)
上一页 2024年12月9日 下午2:37
下一页 2024年12月10日 上午9:40

相关推荐

  • WP Fastest Cache:一款站长必备的 WordPress 页面缓存插件

    WP Fastest Cache 是一款广受好评的 WordPress 缓存插件,旨在通过减少服务器负载和提高页面加载速度来优化网站性能。它通过生成静态 HTML 文件来缓存动态内容,从而显著提升网站的响应速度。这款插件简单易用,适合各种技术水平的用户,无论是初学者还是高级开发者都能轻松上手。 WP Fastest Cache 作为一款备受站长欢迎的 Wor…

    2024年12月12日
    10000
  • WordPress更换数据库前缀后管理员无法登陆后台

    技术宅心血来潮,给网站数据库更换了前缀,更换后发现管理员角色没了,一番折腾发现WordPress更换数据库前缀没那么简单,我们还要将对应数据表中的option_name和meta_key中的部分前缀更换为新的前缀。 我们就需要在数据库中执行以下SQL: UPDATE new_options SET option_name = REPLACE(option_n…

    2024年12月10日
    11200
  • WordPress 为一定时间内发表的文章添加特殊样式

    要为WordPress网站上一定时间内发表的文章添加特殊样式,您可以使用WordPress的自定义CSS功能或在主题文件中进行编辑。下面我将为您提供两种方法: 方法一:使用WordPress自定义CSS功能 登录到您的WordPress后台:打开WordPress网站,并使用管理员凭据登录。 找到自定义CSS选项:在WordPress仪表板中,依次点击“外观…

    2024年12月12日
    12200
  • 如何通过WordPress插件实现社交媒体分享

    如何通过WordPress插件实现社交媒体分享 在现代的社交媒体时代,让网站的内容能够方便地分享到各个社交媒体平台上,是提高用户互动和扩展网站影响力的重要手段之一。WordPress作为最流行的内容管理系统之一,提供了丰富的插件来实现社交媒体分享功能。本文将介绍如何通过WordPress插件实现社交媒体分享,并提供代码示例。 一、选择插件 WordPress…

    2024年12月10日
    12000
  • WordPress 标签云函数 wp_tag_cloud() 使用方法详解

    在 WordPress 开发中,wp_tag_cloud() 函数是一个非常有用的工具,用于生成网站的标签云(Tag Cloud)。标签云不仅有助于网站的美观设计,还能提高用户体验,让用户更容易发现相关内容。在为篇文章中大眼仔将详细介绍 wp_tag_cloud() 的使用方法及其各个参数的作用。 什么是标签云? 标签云(Tag Cloud)是一种可视化技术…

    2024年12月12日
    10900

联系我们

在线咨询: QQ交谈

邮件:5877546@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信