2014-12-10 2 views
0

우리는 Nginx가 실행중인 서버로 CakePHP 프레임 워크 설치를 이동합니다. 이전 서버에는 Apache가있었습니다. 이 CakePHP에는/app/webroot/폴더를 모두 포함하는 하위 폴더에 여러 하위 설치가 있습니다. 우리는 index.php가 작동하도록 만들었지 만,/app/webroot /에있는 다른 모든 파일들은 javascript와 CSS처럼 링크되어 있지 않습니다.CakePHP Htaccess 2 Nginx 다시 작성

이제 다양한 변형이있는 nginx에서 작동하도록 노력했습니다. 문제는 사이트가 PHP 파일을로드하고 URL 작업을 정리한다는 것입니다./app/webroot/아래에있는 CSS 및 JS 파일로드 중.

우리는 CakePHP가있는 폴더로 사용자를 리디렉션하는 header() 함수가있는 index.php가있는 subdomain.example.com에 루트를 설정하려고합니다. 기본적으로 하위 폴더 아래에 여러 사이트. CakePHP 사이트는 다음과 같습니다. http://subdomain.example.com/subfolder

우리가 시도하고있는 nginx conf는 다음과 같습니다. 나는 효과가없는 다양한 옵션을 시도해 왔습니다.

server { 
    rewrite ^(.*) http://example.com$1 permanent; 
} 

server { 
    listen   80; 
    server_name example.com www.example.com subdomain.example.com; 

    access_log /home/example.com/logs/access.log; 
    error_log /home/example.com/logs/error.log error; 

    root /home/example.com/public_html/; 
    index index.php; 

    gzip_static on; 

    location /subfolder { 
      root /home/example.com/public_html/subfolder/; 
      index index.php; 

      rewrite ^/subfolder/(/.*)$ /app/webroot$1 break; 
      try_files $uri $uri/ /subfolder/app/webroot/index.php?$args; 
    } 

    location = /favicon.ico { 
      log_not_found off; 
      access_log off; 
    } 

    location = /robots.txt { 
      allow all; 
      log_not_found off; 
      access_log off; 
    } 

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
      expires max; 
      log_not_found off; 
    } 

    location ~ \.php$ { 
      try_comles $uri =404; 
      include fastcgi_params; 
      fastcgi_pass unix:/var/run/example.com-php5-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 
+0

1. '/ 홈/example.com/public_html을/케이크 1/응용 프로그램/웹 루트 /'- 최초의 케이크로 열어야합니다'example.com/케이크 1 /''/home/example.com/public_html/cake2/app/webroot /'- 두 번째 케이크는 'example.com/cake2 /'등으로 열어야합니다. 폴더 구조입니까? 2. '/ home/example.com/public_html/images /'(설치 간 공유) 또는'/ home/example.com/public_html/cake2/images /'또는'/ home/example.com/public_html/cake2/app/webroot/images /'? –

답변

0

app/webroot /가 서버 루트가됩니다. 그리고 process index.php 파일을위한 별도의 위치.

예 :

server { 
    listen 80; 
    server_name yourserver.com; 

    root /web/path/; 
    index index.php; 

    location/{ 
     rewrite ^(/.*)$ /app/webroot$1 break; 
     try_files $uri $uri/ /app/webroot/index.php?$args; 
    } 

    location ~ \.php$ { 
     try_files $uri =404; 
     include fastcgi_params; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 
+0

죄송합니다, 운이 없습니다. try_files가 작동하지 않는 루프를 추가합니다. – Nookie

+0

설정이 정확히 같거나 다른 위치/다시 쓰기 규칙이 있습니까? 또한 서브 디렉토리에서 index.php를 처리 할 필요가 없다면'try_files $ uri /index.php? $ args;'를'$ uri /'없이 사용할 수 있습니다. –

+1

그것은 당신의 설정과 함께 작동하지만, 내가 얘기 한 것은 서브 디렉토리가 아닌 서브 디렉토리를 루트로 설정하는 것입니다. 우리의 경로는 example.com/folder이고 root는 example.com이어야합니다. index.php가 있으면 누구든지 올바른 폴더로 리디렉션됩니다. 루트를/web/path /로 설정하고 location/example {root/web/path/example/app/webroot /; 그리고 다른 모든 설정은 사이트가 반복되거나 app ​​/ webroot에서 파일을 찾지 못하게합니다. – Nookie