Nginx / Django。从fastcgi_pass中排除路径?

时间:2014-01-16 00:53:05

标签: php django nginx fastcgi

我正在尝试将nginx配置为传递给django fcgi,但是将某些路径排除在路由到django之外,并将一条路径路由到PHP fcgi。我无法正确配置。

以下是我的vhost配置示例:

server {
  listen 80;
  server_name awesome.com;
  #main django fcgi pass
  location / {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:8025;
    fastcgi_split_path_info ^()(.*)$;
  }
  #alias for django static
  location /static {
    alias /var/www/django/awesome/django/static;
  }
  #alias for django media
  location /media {
    alias /var/www/django/awesome/django/media;
  }


  #Below is what I'm trying to figure out.


  #alias /vanilla to generic nginx file serving
  location /vanilla {
    alias /var/www/html/vanilla;
  }

  #pass the PHP scripts for vanilla forums to FastCGI server listening on 127.0.0.1:9000
  location /vanilla/?*\.php$ {
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
       include        fastcgi_params;
       index index.php index.html index.htm;
  }
}

以前任何人都必须做这样的事吗?我不确定如何正确配置这个配置。

1 个答案:

答案 0 :(得分:0)

尝试使用~*修饰符对正则表达式执行不区分大小写(或~区分大小写)匹配:

location ~* ^/vanilla/.+\.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
    include        fastcgi_params;
    index index.php index.html index.htm;
}