当前位置:web 服务器 > Nginx >>

配置nginx支持pathinfo模式的代码和方法

关键部分代码修改如下:

location / {       
    if (!-e $request_filename) {
        rewrite  ^/(.*)$  /index.php/$1  last;
                break;
        }
}
 
location ~ \.php {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fcgi.conf;
    set $real_script_name $fastcgi_script_name;
    if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
        set $real_script_name $1;
        set $path_info $2;
    }
    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
    fastcgi_param SCRIPT_NAME $real_script_name;
    fastcgi_param PATH_INFO $path_info;
}


保存修改,重启nginx,刷新浏览器

贴出nginx.conf代码

user  www www;
 
worker_processes 2;
worker_cpu_affinity 01 10;
 
error_log  /data1/logs/nginx_error.log  crit;
 
pid        /usr/local/webserver/nginx/nginx.pid;
 
worker_rlimit_nofile 65535;
 
events
{
  use epoll;
  worker_connections 65535;
}
 
http
{
  include       mime.types;
  default_type  application/octet-stream;
 
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
 
  sendfile on;
  tcp_nopush     on;
 
  keepalive_timeout 60;
  tcp_nodelay on;
 
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
 
  server
  {
    listen 80;
    server_name a.com;
    index index.php;
    root /data0/htdocs/a.com/www;
 
        location / {       
        if (!-e $request_filename) {
            rewrite  ^/(.*)$  /index.php/$1  last;
                    break;
            }
    }
    
    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fcgi.conf;
        set $real_script_name $fastcgi_script_name;
            if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
            set $real_script_name $1;
            set $path_info $2;
        }
        fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;
    }
  }
}

Apache
IIS
Nginx
Tomcat
如果你遇到web 服务器难题:
访问www.zzzyk.com 试试
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,