문제

내가 작업 한 Zend Framework 기반 사이트는 현재 프로덕션 서버로 마이그레이션되고 있습니다. 이 서버는 nginx (놀라움!)로 판명되었습니다. 당연히 사이트는 Apache에서 개발되었으며 htaccess 파일에 의존하기 때문에 올바르게 작동하지 않습니다.

내 질문은 ... 누구든지 이것에 대한 경험이 있습니까? htaccess 파일이 nginx.conf 파일로 변환하는 방법에 대한 아이디어가 있습니까? 나는 이것을 연구하고 있지만 누군가가 이미 이것에 대해 경험을하기를 바라고 있습니다. 감사!

편집 : 이것은 현재 htaccess입니다.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
도움이 되었습니까?

해결책

나는 그것이 꽤 오래된 실이라는 것을 알고 있지만 어쨌든 어떤 사람들을 도울 수 있습니다.

기본적으로 404 오류를 index.php로 리디렉션하지만 파일이 존재하면 (파일 유형) 오른쪽 루트가 설정됩니다.

나는 내 머리 꼭대기에서 그것을했다. 즉시 작동하지 않을 수 있으며 올바른 경로와 FastCGI 구성을 배치해야합니다. 또한 zend_framework에서와 같이 작동해야하므로 모든 것을 index.php로 다시 넣었습니다.

error_page  404 = /index.php;

location / {
    if (-f $request_filename) {
        root   /var/www;
    }
}

location ~ \.php$ {
        fastcgi_pass   unix:/tmp/php.sock;
        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME     /var/www/index.php;
        include /etc/nginx/fastcgi_params;
}

다른 팁

server {

 listen   80; ## listen for ipv4
 listen   [::]:80 default ipv6only=on; ## listen for ipv6

 server_name  localhost;

 access_log  /var/log/nginx/localhost.access.log;
 error_log  /var/log/nginx/localhost.error.log;

 root   /var/www/localhost/public;

 try_files $uri @php_index;

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location @php_index {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_param  SCRIPT_FILENAME /var/www/localhost/index.php;
  include fastcgi_params;
 }
}

가능하면 try_files를 사용하는 것이 좋습니다.

htaccess-file을 변환하는 자동/체계적인 방법을 모르겠습니다. 수동으로 수행해야 할 것입니다. 그만큼 nginx 위키 Nginx 문서에 가장 적합한 리소스입니다.

편집하다:나는 지금 nginx에서 Zend Framework를 실행하고 있으며 구성은 다음과 같습니다.

server {
  listen 80;
  server_name servername.com;

  root /var/www/zendapp/public;

  location / {
    index index.php;
  }

  # Deny access to sensitive files.
  location ~ (\.inc\.php|\.tpl|\.sql|\.tpl\.php|\.db)$ {
    deny all;
  }
  location ~ \.htaccess {
    deny all;
  }

  # Rewrite rule adapted from zendapp/public/.htaccess
  if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
  }

  # PHP scripts will be forwarded to fastcgi processess.
  # Remember that the `fastcgi_pass` directive must specify the same
  # port on which `spawn-fcgi` runs.
  location ~ \.php$ {
    include /etc/nginx/fastcgi_params;

    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
  }

  location = /50x.html {
      root   /var/www/default;
  }
}

보시다시피, 재 작성 규칙 자체는 매우 간단합니다.

이것은 "공식"이고 간단하며 훌륭합니다.

http://wiki.nginx.org/zend_framework#time_for_nginx

도움이 될 수있는 스테이징 서버;)

            fastcgi_param APPLICATION_ENV staging;

실제로 Zend Framework : One Index.php as bootstrap과 같은 Drupal 사이트가있는 Nginx를 실행합니다.

이것은 규칙입니다 (Zend 프레임 워크에서 테스트되지 않고 Drupal에서는 비슷해야합니다).

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

error_page  404              /index.php;

프로젝트와 같은 하위 디렉토리를 사용하는 경우 http : //some.url/myproject/controller/, 그런 다음 부트 스트랩 파일에 SetBaseUrl을 추가해야합니다.

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initSomeFancyName()
    {
        $this->bootstrap('frontController');
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->setBaseUrl('/myproject'); // set the base url!
    }
}

Nginx 재 작성은 다음과 같습니다.

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

추신 : 물음표는 오타가 아닙니다!

가능하다면 Nginx 상자에서만 액세스 할 수있는 비표준 포트에 Apache를 설정하고 Nginx 프록시에 Apache에 Apache를 설치하는 것이 좋습니다.

Nginx 프록시 문서

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top