jasonstar 发表于 2019-3-31 15:23:49

LNMP1.5安装Nextcloud伪静态问题

lnmp1.5安装Nextcloud,开启pathinfo,php7.1 。参考其官网https://docs.nextcloud.com/server/15/admin_manual/installation/nginx.htmllocation / {
                        rewrite ^ /index.php$request_uri;
                  }


写的nginx伪静态不生效,无法去掉index.php。

以下贴我的全部nginx配置文件
server
    {
      listen 443 ssl;
      #listen [::]:80;
      server_name sync.81pla.cn ;
      index index.html index.htm index.php default.html default.htm default.php;
      root/home/wwwroot/sync.81pla.cn;
ssl_certificate /home/cert/sync.pem;
      ssl_certificate_key /home/cert/sync.key;
      ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_prefer_server_ciphers on;
      ssl_session_cache shared:SSL:10m;
                add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";


      include rewrite/none.conf;
      #error_page   404   /404.html;

      # Deny access to PHP files in specific directory
      #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
                location / {
                        rewrite ^ /index.php$request_uri;
                  }

      include enable-php-pathinfo.conf;

      location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
      {
            expires      30d;
      }

      location ~ .*\.(js|css)?$
      {
            expires      12h;
      }

      location ~ /.well-known {
            allow all;
      }

      location ~ /\.
      {
            deny all;
      }

      access_log/home/wwwlogs/sync.81pla.cn.log;
    }



licess 发表于 2019-3-31 20:26:56

nginx添加上伪静态后需要reload或restart后才会生效,不报错生效后地址栏url里去掉index.php再测试

jasonstar 发表于 2019-3-31 20:43:00

licess 发表于 2019-3-31 20:26
nginx添加上伪静态后需要reload或restart后才会生效,不报错生效后地址栏url里去掉index.php再测试 ...

重启过的lnmp restart
但是不生效的, 手动在地址栏里去掉index.php,自动跳转回带index.php的

jasonstar 发表于 2019-3-31 21:34:23

licess 发表于 2019-3-31 20:26
nginx添加上伪静态后需要reload或restart后才会生效,不报错生效后地址栏url里去掉index.php再测试 ...

部分生效的。。。感觉是Nextcloud的问题。。


伪静态写这条
location / {
rewrite ^ /index.php$uri;
}
首页是没用的, https://xxx.com/index.php/apps/files/?dir=/&fileid=7
即使手动去掉index.php,https://xxx.com/apps/files/?dir=/&fileid=7!也会跳转回index.php的

像 https://xxx.com/index.php/settings/user手动去掉index.php,https://xxx.com/settings/user 是可以正常使用的!!

全网Google了也没找到解决办法,呜呜~

licess 发表于 2019-4-1 09:28:28

jasonstar 发表于 2019-3-31 21:34
部分生效的。。。感觉是Nextcloud的问题。。




看官网上nextcloud的规则有点多,建议直接还是官网配置上改吧

server {
    listen 80;
    listen [::]:80;
    server_name lnmp.org www.lnmp.org;
    root /home/wwwroot/nextcloud;

    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;
    add_header Referrer-Policy no-referrer;

    # 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;
    }

    # The following 2 rules are only needed for the user_webfinger app.
    # Uncomment it if you're planning to use this 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;

    # The following rule is only needed for the Social app.
    # Uncomment it if you're planning to use this app.
    # rewrite ^/.well-known/webfinger /public.php?service=webfinger last;

    location = /.well-known/carddav {
      return 301 $scheme://$host/remote.php/dav;
    }
    location = /.well-known/caldav {
      return 301 $scheme://$host/remote.php/dav;
    }

    # set max upload size
    client_max_body_size 512M;
    fastcgi_buffers 64 4K;

    # Enable gzip but do not remove 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;

    location / {
      rewrite ^ /index.php$request_uri;
    }

    location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
      deny all;
    }
    location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
      deny all;
    }

    location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v|updater\/.+|oc-provider\/.+)\.php(?:$|\/) {
      fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
      include fastcgi.conf;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      #Avoid sending the security headers twice
      fastcgi_param modHeadersAvailable true;
      fastcgi_param front_controller_active true;
      fastcgi_pass unix:/tmp/php-cgi.sock;
      fastcgi_intercept_errors on;
      fastcgi_request_buffering off;
    }

    location ~ ^\/(?:updater|oc-provider)(?:$|\/) {
      try_files $uri/ =404;
      index index.php;
    }

    # Adding the cache control header for js and css files
    # Make sure it is BELOW the PHP block
    location ~ \.(?:css|js|woff2?|svg|gif)$ {
      try_files $uri /index.php$request_uri;
      add_header Cache-Control "public, max-age=15778463";
      add_header X-Content-Type-Options nosniff;
      add_header X-XSS-Protection "1; mode=block";
      add_header X-Robots-Tag none;
      add_header X-Download-Options noopen;
      add_header X-Permitted-Cross-Domain-Policies none;
      add_header Referrer-Policy no-referrer;
      access_log off;
    }

    location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
      try_files $uri /index.php$request_uri;
      access_log off;
    }
}

jasonstar 发表于 2019-4-1 09:53:31

这份nginx配置文件是好使的啦!!谢谢军哥

孤鸿掠影 发表于 2019-11-21 10:48:08

借楼请教一下军哥,我也是nextcloud,但是我环境是lnmpa怎么配置伪静态呢?谢谢!!

licess 发表于 2019-11-21 16:44:53

孤鸿掠影 发表于 2019-11-21 10:48
借楼请教一下军哥,我也是nextcloud,但是我环境是lnmpa怎么配置伪静态呢?谢谢!! ...

正常 lnmp vhost add 添加虚拟主机
添加完成后,修改nginx的对应域名的虚拟主机配置
将前面配置文件里fastcgi_pass unix:/tmp/php-cgi.sock; 改成 proxy_pass http://127.0.0.1:88;
include fastcgi.conf; 改成 include proxy.conf; 然后替换该域名的nginx虚拟主机配置文件
重庆nginx

孤鸿掠影 发表于 2019-12-2 15:45:40

licess 发表于 2019-11-21 16:44
正常 lnmp vhost add 添加虚拟主机
添加完成后,修改nginx的对应域名的虚拟主机配置
将前面配置文件里f ...

谢谢军哥,已经OK了
页: [1]
查看完整版本: LNMP1.5安装Nextcloud伪静态问题