0

我正在尝试将工作的 ExpressionEngine 安装从 Apache 环境迁移到另一个盒子上的 NginX 环境。.htaccess我在尝试将一些重写转换为 NginX时遇到了问题。

该站点使用多语言模块,因此需要为每种其他语言自定义重写规则。

这是我的标准虚拟主机配置,它似乎让 ExpressionEngine 工作得很好(没有多语言模块):

server {
  listen        80;
  server_name   domain.co.uk www.domain.co.uk;
  root          /var/www/vhosts/domain.co.uk/http;

  # Redirects non-www to www
  if ($host = 'domain.co.uk') {
    rewrite ^/(.*) http://www.domain.co.uk/$1 permanent;
  }

  access_log    /var/www/vhosts/domain.co.uk/log/access.log;
  error_log     /var/www/vhosts/domain.co.uk/log/error.log;

  location / {
    index       index.html index.htm index.php;
    # Removes index.php from URLs
    if (!-e $request_filename) {
      rewrite ^/(.*)$ /index.php/$1 last;
    }
  }

  # Standard pass for all PHP files
  location ~ \.php$ {
    include       fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME /var/www/vhosts/domain.co.uk/http$fastcgi_script_name;
  }

  # This is where all the ExpressionEngine magic happens
  location ~ \.php($|/) {
    include       fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;

    set           $script $uri;
    set           $path_info "";

    if ($uri ~ "^(.+\.php)(/.+)") {
      set         $script $1;
      set         $path_info $2;
    }

    fastcgi_param SCRIPT_FILENAME /var/www/vhosts/domain.co.uk/http$script;
    fastcgi_param SCRIPT_NAME $script;
    fastcgi_param PATH_INFO $path_info;
  }
}

以上似乎工作得很好,并做了我想要的。多语言模块文档基于 Apache 设置。对于每种其他语言,它都需要一个具有自己的 htaccess 重写规则的目录 - 有点像这样:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.co\.uk$
RewriteRule (.*) http://www.domain.co.uk/ar/$1 [R=301,L]

# Remove index.php
RewriteCond $1 !^(index\.php) [NC]
RewriteRule ^(.*)$ /de/index.php/$1 [L]

我通过添加以下内容重新创建了上述规则:

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

当我尝试访问时,添加上述内容只会让我看到 404 错误页面http://www.domain.co.uk/de/my_page

fcgi_param SCRIPT FILENAME所以,我认为这可能de

fastcgi_param SCRIPT_FILENAME /var/www/vhosts/spectrumhealthcare.co.uk/http/de$script;

当我访问时,现在这样做会给我一个No input file specified错误http://www.domain.co.uk/de/my_page

我现在有点像一堵墙,所以真正帮助 SO 社区可以帮助我。你还没有让我失望:)。

4

2 回答 2

1

我可以回答我自己的问题。看起来我的语言重写规则略有错误。应该是这样的:

location /de {
  if (!-e $request_filename) {
    rewrite ^/de/(.*)$ /de/index.php/$1 last;
  }
}
于 2010-02-14T19:20:03.273 回答
0

应该直截了当,在默认语言的 nginx 站点配置文件中,您可以执行以下操作:

location / {
  try_files $uri $uri/ /index.php?q=$uri&$args;
}

对于其他语言支持(比如 de/da/fr/ 等):

location /de {
  try_files $uri $uri/ /de/index.php?q=$uri&$args;
}
于 2014-06-11T12:42:45.090 回答