thinkphp ,laravel,yii2在【nginx,apache】的运行配置

  • baagee 发布于 2017-01-18 22:13:37
  • 分类:PHP
  • 967 人围观
  • 2 人喜欢
ThinkPHP5框架nginx配置:

tp5在nginx支持这块做的不够好,因为tp框架需要依赖一个服务变量 path_info ,这个变量nginx已经不再使用了,所以需要自己定义。

server {    
    charset utf-8;    
    client_max_body_size 128M;    
    listen 80;    
    server_name xxx.com;    
    root  /home/www/tp5/public;    
    index  index.php;    
    
    location ~* \.(eot|otf|ttf|woff)$ {    
        add_header Access-Control-Allow-Origin *;    
    }    
    
    location / {    
        index    index.html index.php;    
        if ( -f $request_filename) {    
            break;    
        } 
       
        if ( !-e $request_filename) {    
            rewrite ^/(.*)$ /index.php/$1 last;    
            break;    
        }    
    }    
    
    location ~ \.php {    
        set $script $uri;    
        set $path_info "";    
        if ($uri ~ "^(.+\.php)(/.+)") {    
            set $script $1;    
            set $path_info $2;    
        }    
    include   fastcgi_params;    
    fastcgi_index    index.php?IF_REWRITE=1;    
    fastcgi_pass   127.0.0.1:9000;    
    fastcgi_param    PATH_INFO    $path_info;    
    fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;    
    fastcgi_param    SCRIPT_NAME    $script;    
    try_files $uri =404;    
    }    
}

Laravel框架nginx配置:

server {    
    charset utf-8;
    client_max_body_size 128M;    
    listen 80;    
    server_name xxx.com;    
    root  /home/www/laravel/public;    
    index  index.php;    
    
    location ~* \.(eot|otf|ttf|woff)$ {    
        add_header Access-Control-Allow-Origin *;    
    }    
    
    location / {    
        try_files $uri $uri/ /index.php?$args;    
    }   
     
    location ~ \.php$ {    
        include   fastcgi_params;
        fastcgi_index    index.php;
        fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;    
        fastcgi_pass   127.0.0.1:9000;    
        try_files $uri =404;    
    }    
}

yII2框架的nginx配置:

server {    
    charset utf-8;    
    client_max_body_size 128M;    
    listen 80;    
    server_name xxx.com;    
    root  /home/www/yii2/web;    
    index  index.php;    
    
    location ~* \.(eot|otf|ttf|woff)$ {    
        add_header Access-Control-Allow-Origin *;    
    }    
    
    location / {    
        try_files $uri $uri/ /index.php?$args;    
    }   
     
    location ~ \.php$ {    
        include   fastcgi_params;
        fastcgi_index    index.php;
        fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;    
        fastcgi_pass   127.0.0.1:9000;    
        try_files $uri =404;    
    }    
}

apache的配置对于三大框架来说是一样的:

<VirtualHost *:8888>    
    ServerName xxx.com
    DocumentRoot /home/www/tp5/public/     
</VirtualHost>


标签: apache php yii2 nginx

评论

点击图片切换
还没有评论,快来抢沙发吧!