2013-06-03 27 views
0

我在/ var/www中有一個CodeIgniter項目。我們將稱這個項目爲proj。所以我在/ var/www中有大量文件,在/ var/www/proj中有一個CodeIgniter項目。我迫切需要一個支持這個的Nginx配置。我應該做一個虛擬主機嗎?例如:/var/www/somewebsite.com/和/var/www/proj.somewebsite.com/。你能提供一個支持這個的工作Nginx + CodeIgniter配置嗎?CodeIgniter + Nginx +其他文件在/ var/www

我目前沒有使用域名。我只是在一個VPS上。

謝謝!

回答

0

是的。你必須使用虛擬主機,或者創建服務器來監聽不同的端口,否則服務器將如何知道服務的位置?除非你的意思是像localhost/myporject1/localhost2/myproject2?然後就設置服務器指向根/var/www和FastCGI的調整路徑CI

server { 
     listen 80; 
     server_name localhost; 
     root /var/www/; 


     location ~ /\. { 
       deny all; 
     } 

     #you codigniter project 
     location /yourcodigniterproject { 
       index index.html index.php; 
       try_files /cache$uri @web; 

     } 
     #your other project (if usign php replicate the top with difrent directives) 
     location /yourotherproject { 
       index index.html index.php; 
       try_files /cache$uri $uri 

     } 

     location @web { 
       client_max_body_size 10M; 
       expires 0; 
       fastcgi_pass unix:/var/run/php5-fpm.sock; 
       include /etc/nginx/fastcgi_params; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME /var/www/yourcodigniterproject/index.php; 
       fastcgi_param PATH_INFO $fastcgi_script_name; 
     } 
} 

但正如所說,創建虛擬主機更容易維護。創建各一sites-available條目(假設你正在起訴Linux的),並添加然後爲你ln -sin網站,enabled`

我配置一樣,去刪除它們。一個虛擬服務器有一個站點codeignoter設置,另一個只是普通的靜態網站,一個用於phpmyadmin等...