q6542125 发表于 2018-11-16 13:43:20

Nginx如何通过rewrite支持各种php框架

  公司在开发新站点,所使用的框架式Drupal7.(挺蛋疼的一个框架,遇到不少问题,以后慢慢发上来)
  在这里先介绍一下如何让nginx支持drupal,因为在apache是默认支持.htaccess文件的.所以一般的框架跑在apache上都是没问题的.但是nginx并不支持,其实大体意思是一样的只不过是语法不一样.所以就需要我们对照着原本站点的.htaccess文件把他的语句改写成nginx的rewrite语法.
  这里先把我的配置发出来吧.
  drupal框架--nginx重写
  location / {
  if (!-e $request_filename) {
  rewrite ^/(.*)$ /index.php?q=$1 last;
  }
  其实只需要这一句就可以解决了.
  下面会附加一些之前公司所用其他PHP框架的nginx重写.
  ThinkPHP框架--nginx重写
  location / {
  if (!-e $request_filename){
  rewrite ^/(.*)$ /index.php?url=$1 last;
  }
  CI框架--nginx重写
  server
  {
  ……
  ……
  if ($request_filename !~* /(js|css|images|index.php)) {\\这里
  rewrite ^/$ /index.php last;               \\必须
  rewrite ^/(.*)$ /index.php/$1 last;            \\要写
  }
  location ~ \\.php{
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  set $path_info "";                     \\这里
  set $real_script_name $fastcgi_script_name;      \\必
  if ($fastcgi_script_name ~ "^(.+?\\.php)(/.+)$"){   \\须
  set $real_script_name $1;               \\要
  set $path_info $2;                   \\写
  }                           \\上
  include fastcgi.conf;
  fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;\\这里
  fastcgi_param SCRIPT_NAME $real_script_name;         \\必须
  fastcgi_param PATH_INFO $path_info;               \\要写
  }
  }
  如果以后碰到别的我会在补上的。 目前接触的站点只有这三种

页: [1]
查看完整版本: Nginx如何通过rewrite支持各种php框架