Nginx支持thinkphp pathinfo模式

Nginx默认不支持thinkphp的pathinfo 模式,无奈只能修改nginx配置。修改后的配置如下:

1.nginx.conf:

user  apache apache;

worker_processes  16;

worker_cpu_affinity auto;

pid        /var/run/nginx.pid;

worker_rlimit_nofile 51200;

events {

use epoll;

worker_connections  51200;

}

http {

include       mime.types;

default_type  application/octet-stream;

#charset gb2312;

charset utf-8;

server_names_hash_bucket_size 128;

client_max_body_size 10m;

log_format main ‘$time_local\t$server_addr\t$request_uri\t$query_string\t$request_time\t$remote_addr\t‘

‘$http_x_forwarded_for\t$http_user_agent\t‘

‘$http_cookie\t$http_referer\t$server_name\t$status‘;

access_log on;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 128k;

fastcgi_buffers 4 128k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

fastcgi_intercept_errors on;

gzip on;

gzip_min_length  1k;

gzip_buffers     16 32k;

gzip_http_version 1.1;

gzip_types  text/plain application/x-javascript text/css application/xml;

include conf.d/*;

}

2.fastcgi.conf

fastcgi_pass  127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param  REDIRECT_STATUS    200;

3.conf.d/vhost.conf:

server {

listen       80;

index index.php;

root /data/www/wwwroot/;

#location ~ .*\.php?$ {

#    include     fastcgi.conf;

#    access_log  /var/log/nginx/vhost_access.log;

#}

location / {      

            if (!-e $request_filename) {

                rewrite  ^/(.*)$  /index.php/$1  last;

                break;

           }

        }

  

        location ~ \.php {

            include     fastcgi.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支持thinkphp pathinfo模式

时间: 2024-10-27 01:09:24

Nginx支持thinkphp pathinfo模式的相关文章

nginx 支持thinkphp pathinfo模式

server {listen  80;server_name     apply.lalagome.cn;root /usr/local/www/gome;error_page  404 500 502 503 504  /50x.html;index index.html index.htm index.php ;location / {        index  index.php;        if (!-e $request_filename) {        rewrite  ^

nginx中配置pathinfo模式示例

要想让nginx支持PATH_INFO,首先需要知道什么是pathinfo,为什么要用pathinfo? pathinfo不是nginx的功能,pathinfo是php的功能. php中有两个pathinfo,一个是环境变量$_SERVER['PATH_INFO']:另一个是pathinfo函数,pathinfo() 函数以数组的形式返回文件路径的信息;. nginx能做的只是对$_SERVER['PATH_INFO]值的设置. 下面我们举例说明比较直观.先说php中两种pathinfo的作用,

使Nginx支持ThinkPHP框架

一.nginx不支持thinkphp的原因 ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL' => 2 即可.在Apache下只需要开启mod_rewrite模块就可以正常访问了,但是Nginx中默认是不支持PATHINFO的,所以nginx默认情况下是不支持thinkphp的.不过我们可以通过修改nginx的配置文件来让其支持thinkphp. 二.让nginx支持pathinfo,支持thinkphp 1

nginx下开启pathinfo模式

第一种方式是通过重写url来实现pathinfo模式: 1 location / { 2 if (!-e $request_filename){ 3 rewrite ^/(.*)$ /index.php?s=/$1 last; 4 } 5 } 第二种方式 ,改变 \.php的 1 location ~ \.php { 2 #fastcgi_pass 127.0.0.1:9000; 3 #fastcgi_pass unix:/dev/shm/php-cgi.sock; 4 fastcgi_pass

修改nginx配置文件支持Thinkphp pathinfo以及rewrite模式

server { listen 80; server_name localhost; include /etc/nginx/default.d/*.conf; root /usr/share/nginx/thinkercms; location / { index index.php; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } } location ~ .+\.php($|/) { set

CentOS7 nginx简单配置pathinfo模式(ThinkPHP)

location ~ \.php {    #去掉$ root          H:/PHPServer/WWW; 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_FILENA

配置nginx支持thinkphp框架

因为nginx本身没有支持pathinfo,所以无法使用thinkphp框架,不过我们可以在配置里进行修改使其能够正常使用thinkphp. 1.修改配置支持pathinfo vi /etc/nginx/cong.d/default.conf 在nginx的配置中添加 location ~ \.php/?.*$ {      root html;         #这里的路径需要注意一下,自己之前几次配置错误都是因为从网上直接粘贴的路径不对        fastcgi_pass   127.0

lnmp1.2支持ThinkPhp pathinfo及rewrite

一.pathinfo支持方法 1.2版本系统已经自动生成了一个pathinfo的配置文件,但实测不可用,所以我们先找打这个文件并修改其内容,文件路径为:/usr/local/nginx/pathinfo.conf,将内容修改如下: set $path_info ""; #定义变量 $real_script_name,用于存放真实地址 set $real_script_name $fastcgi_script_name; #如果地址与引号内的正则表达式匹配 if ($fastcgi_sc

配置Nginx支持ThinkPHP

location / { root   /usr/share/nginx/html; index  index.html index.htm; if (!-e $request_filename) { rewrite ^/index.php(.*)$ /index.php?s=$1 last; rewrite  ^(.*)$  /index.php?s=$1  last; break; } }