【问题标题】:Nginx / Django. Excluding path from fastcgi_pass?Nginx / Django。从 fastcgi_pass 中排除路径?
【发布时间】:2014-02-04 17:59:12
【问题描述】:

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

这是我的虚拟主机配置示例:

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;
  }
}

以前有人必须这样做吗?我不确定如何正确配置此配置。

【问题讨论】:

  • 这个配置的行为是什么?每个发送到 django 的请求?
  • 是的,每个请求都进入 django,/static 和 /media 别名工作正常,但我试图让 /vanilla 路径正常工作。它继续被路由到 django。

标签: php django nginx fastcgi


【解决方案1】:

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

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;
}

【讨论】:

  • 如果 URL 是“awesome.com/vanilla/index.php”,这可以正常工作,但由于某种原因,“awesome.com/vanilla/”没有正确使用 php 的索引。还有其他想法吗?
  • 尝试将index index.php index.html index.htm;移动到位置块上方?
猜你喜欢
  • 2018-07-18
  • 1970-01-01
  • 2020-04-04
  • 2011-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-05
相关资源
最近更新 更多