VPS侦探论坛

 找回密码
 注册
查看: 3684|回复: 3

求助:搞不定Lnmp 下 Drupal 8 伪静态

[复制链接]
发表于 2017-1-13 23:45:31 | 显示全部楼层 |阅读模式

我在LNMP 1.3 下安装了Drupal 8.2.5,创建vhost时候选择了rewrite=drupal,所以我按照Nginx官网对Drupal 8的设置脚本, 对 /usr/local/nginx/conf/drupal.conf 做了如下修改
  1. #if (!-e $request_filename) {
  2. #      rewrite ^/(.*)$ /index.php?q=$1 last;
  3. #    }

  4.     location = /favicon.ico {
  5.         log_not_found off;
  6.         access_log off;
  7.     }

  8.     location = /robots.txt {
  9.         allow all;
  10.         log_not_found off;
  11.         access_log off;
  12.     }

  13.     # Very rarely should these ever be accessed outside of your lan
  14.     location ~* \.(txt|log)$ {
  15.         allow 192.168.0.0/16;
  16.         deny all;
  17.     }

  18.     location ~ \..*/.*\.php$ {
  19.         return 403;
  20.     }

  21.     location ~ ^/sites/.*/private/ {
  22.         return 403;
  23.     }

  24.     # Allow "Well-Known URIs" as per RFC 5785
  25.     location ~* ^/.well-known/ {
  26.         allow all;
  27.     }

  28.     # Block access to "hidden" files and directories whose names begin with a
  29.     # period. This includes directories used by version control systems such
  30.     # as Subversion or Git to store control files.
  31.     location ~ (^|/)\. {
  32.         return 403;
  33.     }

  34.     location / {
  35.         # try_files $uri @rewrite; # For Drupal <= 6
  36.         try_files $uri /index.php?$query_string; # For Drupal >= 7
  37.     }

  38.     location @rewrite {
  39.         rewrite ^/(.*)$ /index.php?q=$1;
  40.     }

  41.     # Don't allow direct access to PHP files in the vendor directory.
  42.     location ~ /vendor/.*\.php$ {
  43.         deny all;
  44.         return 404;
  45.     }

  46.     # In Drupal 8, we must also match new paths where the '.php' appears in
  47.     # the middle, such as update.php/selection. The rule we use is strict,
  48.     # and only allows this pattern with the update.php front controller.
  49.     # This allows legacy path aliases in the form of
  50.     # blog/index.php/legacy-path to continue to route to Drupal nodes. If
  51.     # you do not have any paths like that, then you might prefer to use a
  52.     # laxer rule, such as:
  53.     #   location ~ \.php(/|$) {
  54.     # The laxer rule will continue to work if Drupal uses this new URL
  55.     # pattern with front controllers other than update.php in a future
  56.     # release.
  57.     location ~ '\.php$|^/update.php' {
  58.         fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
  59.         # Security note: If you're running a version of PHP older than the
  60.         # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
  61.         # See http://serverfault.com/q/627903/94922 for details.
  62.         include fastcgi_params;
  63.         # Block httpoxy attacks. See https://httpoxy.org/.
  64.         fastcgi_param HTTP_PROXY "";
  65.         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  66.         fastcgi_param PATH_INFO $fastcgi_path_info;
  67.         fastcgi_param QUERY_STRING $query_string;
  68.         fastcgi_intercept_errors on;
  69.         # PHP 5 socket location.
  70.         fastcgi_pass unix:/tmp/php-cgi.sock;
  71.         # PHP 7 socket location.
  72.         #fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
  73.     }

  74.     # Fighting with Styles? This little gem is amazing.
  75.     # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
  76.     location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
  77.         try_files $uri @rewrite;
  78.     }

  79.     # Handle private files through Drupal. Private file's path can come
  80.     # with a language prefix.
  81.     location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
  82.         try_files $uri /index.php?$query_string;
  83.     }

  84.     location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
  85.         expires max;
  86.         log_not_found off;
  87.     }
复制代码
其中按照帖子 https://bbs.vpser.net/viewthread.php?tid=13776&highlight=drupal%2B8 里面军哥所述,我设置了
nmp的fastcgi_pass unix:/tmp/php-cgi.sock;

现在网站能运行,也没有502错误,但是当我安装theme的时候,出现以下错误
An error has occurred.
Please continue to the error page

An AJAX HTTP error occurred.
HTTP Result Code: 403
Debugging information follows.
Path: /core/authorize.php/core/authorize.php?batch=1&id=8&op=do_nojs&op=do
StatusText: Forbidden
ResponseText:
403 Forbidden
403 Forbidden
nginx



错误页面显示如下:
  • Notice: Undefined index: log in update_authorize_install_batch_finished()(line 293 of core/modules/update/update.authorize.inc).
  • Warning: Invalid argument supplied for foreach() in update_authorize_install_batch_finished() (line 293 of core/modules/update/update.authorize.inc).
  • Notice: Undefined index: log in update_authorize_install_batch_finished()(line 334 of core/modules/update/update.authorize.inc).
  • Notice: Undefined index: tasks in update_authorize_install_batch_finished()(line 335 of core/modules/update/update.authorize.inc).
  • Installation failed! See the log below for more information.


折腾很久了,一直搞不定,请大侠指点以下出路吧,谢谢!
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2017-1-14 19:06:38 | 显示全部楼层


drupal以前测试过只需要
location / {
        try_files $uri /index.php?$query_string; # For Drupal >= 7
    }
这一个就行
你这上面有有drupal6的还有7 的,只保留drupal 8的试试
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2017-1-16 12:34:53 | 显示全部楼层

回复 2# 的帖子


代码里 Drupal 6 的都注释掉了啊。我只保留你说的
location / {
        try_files $uri /index.php?$query_string; # For Drupal >= 7
    }

结果还是同样的错
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2017-1-16 12:56:17 | 显示全部楼层



最后搞定了,在网上谷歌了一个帖子,就用Nginx的官方drupal 8 的 recipe,在
  1. location ~ \..*/.*\.php$ {
  2.         return 403;
  3.     }
复制代码


的前面加上一句:
  1. rewrite ^/core/authorize.php/core/authorize.php(.*)$ /core/authorize.php$1;
复制代码



网上有人说用这个解决了问题,我一试也行!

希望对后来人有参考价值。

最后还是感谢军哥!
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-17 00:42 , Processed in 0.025862 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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