VPS侦探论坛

 找回密码
 注册
查看: 6088|回复: 8

LNMP1.5安装Nextcloud伪静态问题

[复制链接]
发表于 2019-3-31 15:23:49 | 显示全部楼层 |阅读模式

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


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

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


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

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

  22.         include enable-php-pathinfo.conf;

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

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

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

  34.         location ~ /\.
  35.         {
  36.             deny all;
  37.         }

  38.         access_log  /home/wwwlogs/sync.81pla.cn.log;
  39.     }
复制代码




美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2019-3-31 20:26:56 | 显示全部楼层


nginx添加上伪静态后需要reload或restart后才会生效,不报错生效后地址栏url里去掉index.php再测试
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2019-3-31 20:43:00 来自手机 | 显示全部楼层

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

重启过的  lnmp restart
但是不生效的, 手动在地址栏里去掉index.php,自动跳转回带index.php的
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 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了也没找到解决办法,呜呜~
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2019-4-1 09:28:28 | 显示全部楼层

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

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

  1. server {
  2.     listen 80;
  3.     listen [::]:80;
  4.     server_name lnmp.org www.lnmp.org;
  5.     root /home/wwwroot/nextcloud;

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

  12.     # Remove X-Powered-By, which is an information leak
  13.     fastcgi_hide_header X-Powered-By;

  14.     location = /robots.txt {
  15.         allow all;
  16.         log_not_found off;
  17.         access_log off;
  18.     }

  19.     # The following 2 rules are only needed for the user_webfinger app.
  20.     # Uncomment it if you're planning to use this app.
  21.     #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
  22.     #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;

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

  26.     location = /.well-known/carddav {
  27.       return 301 $scheme://$host/remote.php/dav;
  28.     }
  29.     location = /.well-known/caldav {
  30.       return 301 $scheme://$host/remote.php/dav;
  31.     }

  32.     # set max upload size
  33.     client_max_body_size 512M;
  34.     fastcgi_buffers 64 4K;

  35.     # Enable gzip but do not remove ETag headers
  36.     gzip on;
  37.     gzip_vary on;
  38.     gzip_comp_level 4;
  39.     gzip_min_length 256;
  40.     gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
  41.     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;

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

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

  51.     location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
  52.         fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
  53.         include fastcgi.conf;
  54.         fastcgi_param PATH_INFO $fastcgi_path_info;
  55.         #Avoid sending the security headers twice
  56.         fastcgi_param modHeadersAvailable true;
  57.         fastcgi_param front_controller_active true;
  58.         fastcgi_pass unix:/tmp/php-cgi.sock;
  59.         fastcgi_intercept_errors on;
  60.         fastcgi_request_buffering off;
  61.     }

  62.     location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
  63.         try_files $uri/ =404;
  64.         index index.php;
  65.     }

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

  79.     location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
  80.         try_files $uri /index.php$request_uri;
  81.         access_log off;
  82.     }
  83. }
复制代码

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2019-4-1 09:53:31 | 显示全部楼层

这份nginx配置文件是好使的啦!!谢谢军哥
发表于 2019-11-21 10:48:08 | 显示全部楼层

借楼请教一下军哥,我也是nextcloud,但是我环境是lnmpa  怎么配置伪静态呢?谢谢!!
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 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
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2019-12-2 15:45:40 | 显示全部楼层


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

谢谢军哥,已经OK了

军哥运维代购:http://shop63846532.taobao.com/

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-8 08:38 , Processed in 0.049030 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表