2016-04-13 78 views
3

我試圖刪除index.php?使用Codeigniter與nginx服務器,但它不工作。我tryed nginx的網站的官方的解決辦法https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/ 其實,在默認的文件,我有以下代碼:如何從Codeigniter(nginx)中刪除index.php

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

     root /var/www; 
     index index.html index.htm index.php; 
     autoindex on; 
     # Make site accessible from http://localhost/ 
     server_name localhost; 



     index index.php; 
location/{ 
    set $page_to_view "/index.php"; 
    try_files $uri $uri/ @rewrites; 
    root /var/www/site; 
    index index.php index.html index.htm; 
} 

location ~ \.php$ { 
    include /etc/nginx/fastcgi_params; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME /var/www/site$page_to_view; 
} 

# rewrites 
location @rewrites { 
    if ($uri ~* ^/([a-z]+)$) { 
     set $page_to_view "/$1.php"; 
     rewrite ^/([a-z]+)$ /$1.php last; 
    } 
} 

} 

而且config.php文件如下:

$config['base_url'] = ''; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

的結果任何請求都是502 Bad Gateway。

回答

0
server { 
    listen  80; 
    server_name localhost; 
    root /var/www/html/ci; 
    autoindex on; 
    index index.php; 

    location/{ 

     try_files $uri $uri/ /index.php; 

     location = /index.php { 

      fastcgi_pass 127.0.0.1:6969; 
      fastcgi_param SCRIPT_FILENAME /var/www/html/ci$fastcgi_script_name; 
      include  fastcgi_params; 
     } 
    } 

    location ~ \.php$ { 
     return 444; 
    } 

}

和配置文件

$config['base_url'] = ""; 
    $config['index_page']  = ""; 
    $config['uri_protocol']  = "AUTO"; 
+0

感謝穆罕默德,但我嘗試之前,實施這一解決方案,它doesn't工作。也許我必須澄清一下,我實現了nginx官方解決方案 – xylander