前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nextcloud宝塔面板nginx伪静态-去除index.php

nextcloud宝塔面板nginx伪静态-去除index.php

作者头像
孤鸿
发布2022-10-04 15:02:06
2.1K0
发布2022-10-04 15:02:06
举报
文章被收录于专栏:孤鸿

一直在用nextcloud作为个人网盘用,前段时间电信赠送了一台vps,重新安装了nextcloud并使用了宝塔面板作为管理工具,安装方法和安装后的报警解决可以参考

CentOS7安装NextCloud

下载安装包wget https://download.nextcloud.com/server/releases/...

修改宝塔PHP配置文件<font color=red>【非常重要,必须要改,否则不生效!!!】</font>
  • 路径:/www/server/nginx/conf
  • 文件名:enable-php-74.conf 根据所使用php版本修改相对应文件

原配置文件内容:

代码语言:javascript
复制
    location ~ [^/]\.php(/|$)
    {
        try_files $uri =404;
        fastcgi_pass  unix:/tmp/php-cgi-74.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        include pathinfo.conf;
    }

在配置文件最后一行加上fastcgi_param front_controller_active true;

完整内容:

代码语言:javascript
复制
    location ~ [^/]\.php(/|$)
    {
        try_files $uri =404;
        fastcgi_pass  unix:/tmp/php-cgi-74.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        include pathinfo.conf;
        fastcgi_param front_controller_active true;
    }
添加nginx伪静态规则和一些其它安全配置
  • 在宝塔面板的伪静态页面添加,也可直接在配置文件里面添加
代码语言:javascript
复制
#(&#x53EF;&#x9009;)&#x6DFB;&#x52A0;&#x5982;&#x4E0B;header&#x4E3B;&#x8981;&#x4E3A;&#x4E86;&#x5B89;&#x5168;
add_header Strict-Transport-Security &quot;max-age=63072000;&quot;;
#&#x89E3;&#x6790;caldav&#x548C;carddav
rewrite /.well-known/carddav /remote.php/dav permanent;
rewrite /.well-known/caldav /remote.php/dav permanent;
#&#x9759;&#x6001;&#x8D44;&#x6E90;&#x91CD;&#x5B9A;&#x5411;1
location ~* \/core\/(?:js\/oc\.js|preview\.png).*$ {
    rewrite ^ /index.php last;
}
#webdav&#x548C;&#x5176;&#x4ED6;&#x6240;&#x6709;&#x8BF7;&#x6C42;&#x91CD;&#x5B9A;&#x5411;&#x5230;index.php&#x4E0A;
location / {
    rewrite ^ /index.php$uri;
    rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
    rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
    rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
    rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
#&#x9759;&#x6001;&#x8D44;&#x6E90;&#x91CD;&#x5B9A;&#x5411;2,&#x652F;&#x6301;&#x4F7F;&#x7528;acme&#x811A;&#x672C;&#x5728;&#x7533;&#x8BF7;&#x8BC1;&#x4E66;&#x65F6;&#x5BF9;&#x57DF;&#x540D;&#x7684;&#x9A8C;&#x8BC1;
    if ($uri !~* (?:\.(?:css|js|svg|gif|png|html|ttf|woff)$|^\/(?:remote|public|cron|status|ocs\/v1|ocs\/v2)\.php|^\/\.well-known\/acme-challenge\/.*$)){
        rewrite ^ /index.php last;
    }
}
#&#x9759;&#x6001;&#x8D44;&#x6E90;&#x91CD;&#x5B9A;&#x5411;3
location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ {
    try_files $uri /index.php$uri$is_args$args;
    access_log off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
    try_files $uri/ =404;
    index index.php;
}
#caldav&#x548C;carddav
rewrite /.well-known/carddav /remote.php/dav permanent;
rewrite /.well-known/caldav /remote.php/dav permanent;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}
#(&#x53EF;&#x9009;)&#x4E3A;&#x4E86;&#x652F;&#x6301;user_webfinger app
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
#&#x652F;&#x6301;&#x65E5;&#x5386;&#x548C;&#x8054;&#x7CFB;&#x4EBA;&#xFF0C;&#x5EFA;&#x8BAE;&#x52A0;&#x4E0A;
location = /.well-known/carddav {
  return 301 $scheme://$host:$server_port/remote.php/dav;
}
location = /.well-known/caldav {
  return 301 $scheme://$host:$server_port/remote.php/dav;
}
#&#x542F;&#x52A8;Gzip,&#x4E0D;&#x8981;&#x5220;&#x9664;ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
#&#x5B89;&#x5168;&#x8BBE;&#x7F6E;&#xFF0C;&#x7981;&#x6B62;&#x8BBF;&#x95EE;&#x90E8;&#x5206;&#x654F;&#x611F;&#x5185;&#x5BB9;
location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
    deny all;
}
location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
    deny all;
}
location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
    deny all;
}
location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
    try_files $uri/ =404;
    index index.php;
}
#&#x8FD9;&#x90E8;&#x5206;&#x5427;&#xFF0C;&#x9ED8;&#x8BA4;&#x5C31;&#x6709;&#xFF0C;&#x4E0D;&#x8FC7;&#x6709;&#x6240;&#x4E0D;&#x540C;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x5408;&#x5E76;&#x4E86;&#x4E0B;&#xFF0C;&#x66FF;&#x6362;&#x539F;&#x6765;&#x7684;&#x5C31;&#x884C;
location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy)\.php(?:$|\/) {
    fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
    set $path_info $fastcgi_path_info;
    try_files $fastcgi_script_name =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param HTTPS on;
    fastcgi_pass unix:/tmp/php-cgi-74.sock;
    # Avoid sending the security headers twice
    fastcgi_param modHeadersAvailable true;
    # Enable pretty urls
    fastcgi_param front_controller_active true;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
}
# Adding the cache control header for js, css and map files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
    try_files $uri /index.php$request_uri;
    add_header Cache-Control &quot;public, max-age=15778463&quot;;
    add_header Referrer-Policy &quot;no-referrer&quot; always;
    add_header X-Content-Type-Options &quot;nosniff&quot; always;
    add_header X-Download-Options &quot;noopen&quot; always;
    add_header X-Frame-Options &quot;SAMEORIGIN&quot; always;
    add_header X-Permitted-Cross-Domain-Policies &quot;none&quot; always;
    add_header X-Robots-Tag &quot;none&quot; always;
    add_header X-XSS-Protection &quot;1; mode=block&quot; always;
    # Optional: Don&apos;t log access to assets
    access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap|mp4|webm)$ {
    try_files $uri /index.php$request_uri;
    # Optional: Don&apos;t log access to other assets
    access_log off;
}

最后重启nginx,清除缓存,使用域名访问,发现index.php已经去掉,分享链接也没有index.php了。也可参考 > > 官方文档

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 修改宝塔PHP配置文件<font color=red>【非常重要,必须要改,否则不生效!!!】</font>
  • 添加nginx伪静态规则和一些其它安全配置
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档