当前位置:首页 » 个人博客 » 正文

说说Drupal10的Nginx伪静态配置

 人参与  2022年10月16日 13:10  分类 : 个人博客  点这评论

自Drupal8开始简洁网址(clean urls)国内常称为伪静态是drupal运行必要需求之一,如果你使用的是Nginx服务器,你会发现安装drupal10后除了首页可以打开,进入后台提示“404页面没有找到”,这是由于Drupal的开发和部署大多数都是在Apache上完成的,因此对于使用apache的服务器,通常只需要启用apache的“mod_rewrite”扩展即可满足drupal伪静态需求。而nginx服务器则需要配置drupal的nginx静态规则,才能正常运行drupal10。

1016131028131.jpg

Drupal10的nginx伪静态规则。

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  ssl_certificate /usr/local/tengine/conf/ssl/atuwe.com.crt;
  ssl_certificate_key /usr/local/tengine/conf/ssl/atuwe.com.key;
  ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
  ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 10m;
  ssl_session_cache builtin:1000 shared:SSL:10m;
  ssl_buffer_size 1400;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name www.atuwe.com www.atuwe.com;
  access_log off;
  index index.html index.htm index.php;
  root /data/wwwroot/atuwe/web;
  if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
  if ($host != atuwe.com) {  return 301 $scheme://atuwe.com$request_uri;  }
  
  #上面是网站的SSL和路径配置,非drupal10配置,不要复制
  
  #drupal10的nginx伪静态规则从这里开始。
  
      location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    # Very rarely should these ever be accessed outside of your lan
    location ~* \.(txt|log)$ {
        allow 192.168.0.0/16;
        deny all;
    }
    location ~ \..*/.*\.php$ {
        return 403;
    }
    location ~ ^/sites/.*/private/ {
        return 403;
    }
    # Block access to scripts in site files directory
    location ~ ^/sites/[^/]+/files/.*\.php$ {
        deny all;
    }
    # Allow "Well-Known URIs" as per RFC 5785
    location ~* ^/.well-known/ {
        allow all;
    }
    # Block access to "hidden" files and directories whose names begin with a
    # period. This includes directories used by version control systems such
    # as Subversion or Git to store control files.
    location ~ (^|/)\. {
        return 403;
    }
    location / {
        # try_files $uri @rewrite; # For Drupal <= 6
        try_files $uri /index.php?$query_string; # For Drupal >= 7
    }
    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }
    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }
    # In Drupal 8, we must also match new paths where the '.php' appears in
    # the middle, such as update.php/selection. The rule we use is strict,
    # and only allows this pattern with the update.php front controller.
    # This allows legacy path aliases in the form of
    # blog/index.php/legacy-path to continue to route to Drupal nodes. If
    # you do not have any paths like that, then you might prefer to use a
    # laxer rule, such as:
    #   location ~ \.php(/|$) {
    # The laxer rule will continue to work if Drupal uses this new URL
    # pattern with front controllers other than update.php in a future
    # release.
    location ~ '\.php$|^/update.php' {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        # Security note: If you're running a version of PHP older than the
        # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
        # See http://serverfault.com/q/627903/94922 for details.
        include fastcgi_params;
        # Block httpoxy attacks. See https://httpoxy.org/.
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        # PHP 5 socket location.
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        # PHP 7 socket location.
	  #特别说明,要将下面的php-cgi.sock更改为自己服务器相应文件的路径,否则会报错。
        fastcgi_pass unix:/dev/shm/php-cgi.sock;   
    }
    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }
    # Handle private files through Drupal. Private file's path can come
    # with a language prefix.
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
    }
    #for google adsense
    location = /ads.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
     #以下这行代码修复执行/update.php升级站点,或通过后台安装主题/模块出现错误的bug
	rewrite ^/core/authorize.php/core/authorize.php(.*)$ /core/authorize.php$1;    
}

本站基于Drupal10构建,以上为本站完整的nginx配置规则,如果你使用的宝塔面板或其他面板,请仔细看配置文件中做的注释,php-cgi.sock文件路径必须替换为自己服务器的,如果你不知道这个文件的路径,linux系统服务器可以通过find / -name php-cgi.sock命令定位文件路径。

另外提醒一点,Drupal10的依赖组件和使用的技术比较新,建议使用最新稳定版Nginx或Tengine。

最后附上Nginx官方提供的Drupal配置文件:

https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/


本文由本站原创或投稿者首发,转载请注明来源!

本文链接:http://www.ziti66.com/net/html/25.html

本文标签:Drupal10  Nginx伪静态    

微信公众号:升级接入中

<< 上一篇下一篇 >>
为祖国加油
祖国加油,相信新的一年会更好...
为祖国加油
森林防火,人人有责。祖国加油...

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

相关文章


最新发布:

搜索

网站分类

Tags列表

最新留言

++发现更多精彩++

    海内存知己,天涯若比邻。

黔ICP备2020011602号黔ICP备2020011602号-8
贵公安备52052602000222号

❤安全运行 Copyright © 2018-2023 李烨自媒体 版权所有.

本站采用创作共用版权 CC BY-NC-SA 3.0 CN 许可协议,转载或复制请注明出处