【问题标题】:Running a secondary PHP app from a subdirectory in Nginx从 Nginx 的子目录运行辅助 PHP 应用程序
【发布时间】:2015-02-17 20:40:03
【问题描述】:

我有一个基于 Kirby 平面文件 CMS 构建的站点,它在根目录中运行得很好,但我试图让 FlightPHP 的实例在子目录中运行(称为 crm) 的上述项目。这个FlightPHP 实例将处理表单提交,所以我需要能够正确映射网址。

使用 Apache 和 .htaccess,这很容易:

# make forms/crm links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^crm/(.*) crm/index.php [L]

我似乎无法在 Nginx 上使用它,这是我目前所拥有的:

server {
  listen 80;
  listen [::]:80;
  root /var/www/mainsite;
  index index.php index.html index.htm;
  server_name mydomain.com;
  autoindex on;
  access_log off;

  # Kirby Specific Directories
  rewrite ^/site/(.*) /error permanent;
  rewrite ^/kirby/(.*) /error permanent;    

  add_header X-UA-Compatible "IE=Edge,chrome=1";

  location ~ .php {
      fastcgi_pass  unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_hide_header X-Powered-By;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_script_name;
      fastcgi_buffer_size 128k;
      fastcgi_buffers 256 16k;
      fastcgi_busy_buffers_size 256k;
      fastcgi_temp_file_write_size 256k;        
      include fastcgi_params;            
  }

  location ^~ /crm {
      root /var/www/mainsite/crm;

      if (!-e $request_filename)
      {
          rewrite ^/(.*)$ /index.php/$1 last;
          break;
      }
  } 

  location / {
      try_files $uri $uri/ /index.php?$query_string;
  }   

  location ~* .(?:xml|ogg|mp3|mp4|ogv|svg|svgz|eot|otf|woff|ttf|css|js|jpg|jpeg|gif|png|ico)$ {
    try_files $uri =404;
    expires max;
    access_log off;
    log_not_found off;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  }         
}

我从网上类似的帖子中尝试了很多方法,但没有一个能正常工作。

【问题讨论】:

    标签: php .htaccess nginx kirby flightphp


    【解决方案1】:

    尝试用这个替换您的位置 ^~ /crm 块

    location /crm {
        try_files $uri $uri/ /crm/index.php?$args;
    }
    

    如果那个不能解决,试试

    location /crm {
        try_files $uri $uri/ /crm/index.php?$uri;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-02-23
      • 1970-01-01
      • 2021-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-28
      相关资源
      最近更新 更多