php - 从 Nginx 中的子目录运行辅助 PHP 应用程序

标签 php .htaccess nginx kirby flightphp

我有一个基于 Kirby 构建的网站平面文件 CMS 及其在根目录中运行得很好,但我正在尝试获取 FlightPHP 的实例在上述项目的子目录(称为 crm)中运行。这个FlightPHP实例将处理表单提交,因此我需要能够正确映射 URL。

使用 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";
  }         
}

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

最佳答案

尝试用此替换您的位置 ^~/crm block

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

如果那个不能解决问题,请尝试

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

关于php - 从 Nginx 中的子目录运行辅助 PHP 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27557097/

相关文章:

php - 从 PHP 使用 DOTNET 时遇到问题。

phpMyAdmin 在我的 apache httpd 上显示空白页面

.htaccess - 301 重定向目标 url 格式

php - 用htaccess密码保护识别 "apple-touch-icon"

nginx - 在多个服务器上使用 socketio 和 redis

php - PHP 中的 UTF8 文件名和不同的 Unicode 编码

php - 如何在 WordPress 中为带有斜杠的页面创建自定义 url,如/se/pagename

javascript - Node.js - Nginx 502

python - 可选择在 Django 或 nginx 中限制上传和下载速度

php - 在生产阶段移动 Laravel 项目