2016-11-02 4 views
1

두 개의 PHP 프레임 워크에서 동일한 도메인의 다른 위치에 nginx를 구성해야합니다. example.com/ - CodeIgniter를 (루트의/var/www/html/CodeIgniter의)동일한 도메인에서 codeigniter 및 laravel에 대해 NGINX를 구성하는 방법

example.com/api - 여기 laravel 5.2 (루트의/var/www/html/laravel)

내 예,하지만 그들은 작동하지 않습니다. 첫 번째 예에서

server { 

    listen 80; 
    server_name example.com www.example.com; 
    root /var/www/html/codeigniter; 

    index index.php; 

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

    location ~ \.php$ { 
     try_files $uri /index.php =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors off; 
     fastcgi_buffer_size 16k; 
     fastcgi_buffers 4 16k; 
    } 


    location /api { 
     root /var/www/html/laravel/public/; 
     index index.php index.html index.htm; 

     try_files $uri $uri/ index.php?$query_string; 

     location ~ \.php$ { 
      try_files $uri /index.php =500; 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
      fastcgi_index index.php; 
      include fastcgi_params; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      fastcgi_intercept_errors off; 
      fastcgi_buffer_size 16k; 
      fastcgi_buffers 4 16k;      
     } 


    }  
} 

완벽 example.com/* 노선 codeinginter 작동 하지만 경로에서 작동하지 laravel : 또한

/api - codeigniter return 404 page not found, 
/api/index.php - laravel return 404 because this page not exists, 
/api/user/ -codeigniter also return 404 page 

이 설정되지 작품 :

server { 
     listen 80; 

     server_name example.com; 

     root /var/www/; 

     index index.php index.html index.htm; 

     charset utf-8; 

     access_log /var/log/nginx/example.com-access.log; 
     error_log /var/log/nginx/examplw.com-error.log error; 

     sendfile off; 

     client_max_body_size 100m; 



     location /api { 
       root /var/www/html/laravel/public; 
       index index.php index.html index.htm; 

       try_files $uri $uri/ /index.php?$query_string; 

       location ~ \.php$ { 
         try_files $uri /index.php =500; 
         fastcgi_split_path_info ^(.+\.php)(/.+)$; 
         fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
         fastcgi_index index.php; 
         include fastcgi_params; 
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
         fastcgi_intercept_errors off; 
         fastcgi_buffer_size 16k; 
         fastcgi_buffers 4 16k; 
       } 

       location ~ /\.ht { 
         deny all; 
       } 
     } 

     location/{ 
       root /var/www/html/codeigniter; 
       index index.php index.html index.htm; 

       try_files $uri $uri/ /index.php?$query_string; 

       location ~ \.php$ { 
         fastcgi_split_path_info ^(.+\.php)(/.+)$; 
         fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
         fastcgi_index index.php; 
         include fastcgi_params; 
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
         fastcgi_intercept_errors off; 
         fastcgi_buffer_size 16k; 
         fastcgi_buffers 4 16k; 
       } 

       location ~ /\.ht { 
         deny all; 
       } 
     } 


} 

이 구성도 작동하지 않습니다. example.com - codeigniter는 완벽하게 작동합니다. example.com/api --codeigniter return 404 example.com/api/index.php - laravel return 404

누구든지 올바른 방법으로 구성 할 수 있습니까?

답변

0

에 체크 아웃 :

server { 
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on; 

    root /var/www/; 
    index index.php index.html index.htm; 

    server_name example.com; 

    # CodeIgniter 
    location/{ 
      try_files $uri $uri/ /index.php?$uri&$args; 
    } 

    # deny access to .htaccess files 
    location ~ /\.ht { 
      deny all; 
    } 

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

    location ~ \.php$ { 
      try_files $uri =404; 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include fastcgi_params; 
    } 

}  

장소 디렉토리 안에 당신의 Laravel 인덱스 파일 (index.php)이 /public/api

변경 index.php의 디렉토리를 올바른 bootstrap 파일을

<?php 

/** 
* Laravel - A PHP Framework For Web Artisans 
* 
* @package Laravel 
* @author Taylor Otwell <[email protected]> 
*/ 

/* 
|-------------------------------------------------------------------------- 
| Register The Auto Loader 
|-------------------------------------------------------------------------- 
| 
| Composer provides a convenient, automatically generated class loader for 
| our application. We just need to utilize it! We'll simply require it 
| into the script here so that we don't have to worry about manual 
| loading any of our classes later on. It feels nice to relax. 
| 
*/ 

require __DIR__.'/../../bootstrap/autoload.php'; 

/* 
|-------------------------------------------------------------------------- 
| Turn On The Lights 
|-------------------------------------------------------------------------- 
| 
| We need to illuminate PHP development, so let us turn on the lights. 
| This bootstraps the framework and gets it ready for use, then it 
| will load up this application so that we can run it and send 
| the responses back to the browser and delight our users. 
| 
*/ 

$app = require_once __DIR__.'/../../bootstrap/app.php'; 
+0

이를 호출 예제가 작동하지만 이제 laravel 공용 디렉토리의 모든 파일은 public/api /로 옮겨야합니다.하지만이 나쁜 생각입니다. 어쩌면, 알다시피, codeigniter에서 다른 곳으로 나가면 laravel의 반환 파일을 위해 nginx를 설정하는 방법 – esperant

+0

사실, 하나의 파일 일뿐입니다. 왜 그렇게 나쁜거야? –

+0

또한 Laravel과 CodeIgniter를 공용으로 배치 할 수 없습니다. 두 가지 모두 모든 요청을 처리하는 단일 'index.php'파일과 동일한 아이디어를 사용하기 때문입니다. –

관련 문제