nginx 支持thinkphp 的 PATH_INFO

nginx :  /usr/local/nginx/

php   :  /usr/local/php/

网站根目录: /usr/local/nginx/html/

修改后支持thinkphp的内容:

user  nobody;
worker_processes  1;
error_log  logs/error.log  info;
pid        logs/nginx.pid;
events {
    use epoll;
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
                                                                                                                              
    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php {                   #去掉后面的$
            root           html;
            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  /usr/local/nginx/html$fastcgi_script_name;  # 这个是在配置nginx+php整合的时候就改好的$前面的是网站的主目录
             include        fastcgi_params;
        }
        if (!-e $request_filename)
            {
            #地址作为将参数rewrite到index.php上。
             rewrite ^/(.*)$ /index.php/$1;
            #   若是子目录则使用下面这句,将subdir改成目录名称即可。
            # rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
            #    }
            }
    }
server {
        listen       80;
        server_name  s.abc.org;
        location / {
            root   html;
            index  index.html index.htm;
        }
        location /status {
            stub_status on;
            access_log   on;
            allow 192.168.80.0/24;
        }
    }
}

此条目发表在学习笔记分类目录。将固定链接加入收藏夹。

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据