鍍金池/ 問(wèn)答/PHP  Linux/ 如何配置nginx使得可以方位CI框架?

如何配置nginx使得可以方位CI框架?

我在阿里云服務(wù)器上安裝了nginx,使用PHP的CI框架開(kāi)發(fā),但是配置的nginx的配置文件無(wú)法訪問(wèn)ci框架的其他控制器,只能訪問(wèn)默認(rèn)的welcome控制器。而且也只能訪問(wèn)默認(rèn)控制器的index方法,請(qǐng)問(wèn)我該如何修改?nginx配置文件如下:


  2 #user  nobody;
  3 worker_processes  1;
  4 
  5 #error_log  logs/error.log;
  6 #error_log  logs/error.log  notice;
  7 #error_log  logs/error.log  info;
  8 
  9 #pid        logs/nginx.pid;
 10 
 11 
 12 events {
 13     worker_connections  1024;
 14 }
 15 
 16 
 17 http {
 18     include       mime.types;
 19     default_type  application/octet-stream;
 20 
 21     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 22     #                  '$status $body_bytes_sent "$http_referer" '
 23     #                  '"$http_user_agent" "$http_x_forwarded_for"';
 24 
 25     #access_log  logs/access.log  main;
 26 
 27     sendfile        on;
 28     #tcp_nopush     on;
 29 
 30     #keepalive_timeout  0;
 31     keepalive_timeout  65;
 32 
 33     #gzip  on;
 34 
 35     server {
 36         listen       80;
 37         server_name  106.14.119.56;
 38         root         /var/www/html/myproject;
 39         index       index.html index.htm index.php;
 40 
 41         #charset koi8-r;
 42 
 43         #access_log  logs/host.access.log  main;
 44 
 45         location / {
 46             try_files $uri $uri/ /index.php?$query_string;
 47 
 48             if (-f $request_filename) {
 49                 expires 10d;
 50                 break;
 51             }
 52 
 53             if (!-e $request_filename) {
 54                 rewrite ^/(.*)/$ /index.php/$1 last;
 55             }
 56         }
 57 
 58         location ~ ^(.+\.php)(.*)$ {
 59             fastcgi_index index.php;
 60             fastcgi_split_path_info ^(.+\.php)(.*)$;
 61             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 62             fastcgi_param PATH_INFO $fastcgi_path_info;
 63             fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
 64             fastcgi_pass 127.0.0.1:9000;
 65             fastcgi_intercept_errors on;
 66             include fastcgi_params;
 67         }
 68 
 69 
 70         # redirect server error pages to the static page /50x.html
 71         #
 72         error_page   500 502 503 504  /50x.html;
 73         location = /50x.html {
 74         }
 75
 76         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 77         #
 78         #location ~ \.php$ {
 79         #    proxy_pass   http://127.0.0.1;
 80         #}
 81 
 82         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 83         #
 84         #location ~ \.php$ {
 85         #    root           html;
 86         #    fastcgi_pass   127.0.0.1:9000;
 87         #    fastcgi_index  index.php;
 88         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 89         #    include        fastcgi_params;
 90         #}
 91 
 92         # deny access to .htaccess files, if Apache's document root
 93         # concurs with nginx's one
 94         #
 95         #location ~ /\.ht {
 96         #    deny  all;
 97         #}
 98     }
 99 
100 
101     # another virtual host using mix of IP-, name-, and port-based configuration
102     #
103     #server {
104     #    listen       8000;
105     #    listen       somename:8080;
106     #    server_name  somename  alias  another.alias;
107 
108     #    location / {
109     #        root   html;
110     #        index  index.html index.htm;
111     #    }
112     #}
113 
114 
115     # HTTPS server
116     #
117     #server {
118     #    listen       443 ssl;
119     #    server_name  localhost;
120 
121     #    ssl_certificate      cert.pem;
122     #    ssl_certificate_key  cert.key;
123 
124     #    ssl_session_cache    shared:SSL:1m;
125     #    ssl_session_timeout  5m;
126 
127     #    ssl_ciphers  HIGH:!aNULL:!MD5;
128     #    ssl_prefer_server_ciphers  on;
129 
130     #    location / {
131     #        root   html;
132     #        index  index.html index.htm;
133     #    }
134     #}
135 
136 }
回答
編輯回答
厭遇

沒(méi)有測(cè)過(guò),你試試看

server {
        listen       80;
        listen [::]:80 ipv6only=on;
        server_name  www.example.com;

        root   /data/www/www.example.com;
        index index.php  index.html index.htm;

        location / {
                # 這里使用try_files進(jìn)行url重寫(xiě),不用rewrite了。
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php($|/) {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ /\.ht {
                deny  all;
        }
}
2018年5月30日 03:18