thinkphp5.0 +nginx在contos7下配置访问

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了thinkphp5.0 +nginx在contos7下配置访问相关的知识,希望对你有一定的参考价值。

nginx vhost配置:
server
{
listen 80;
server_name lp.t1.com t1.com;
index index.php;
#根目录设置到Public下
root /home/wwwroot/lp.t1.com/public;

    #定义变量
    set $root /home/wwwroot/lp.t1.com/public;

    location ~ [^/].php(/|$)
    {
        try_files $uri =404;
        fastcgi_pass  unix:/tmp/php-cgi.sock;
        fastcgi_index index.php;
        #设置PATH_INFO
        fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
        #引入fastcgi配置
        include fastcgi.conf;
    }

    #从URL中去掉index.php入口文件
    location /
    {
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

    location ~ .*.(js|css)?$
    {
        expires      12h;
    }

    location ~ /.well-known {
        allow all;
    }

    location ~ /.
    {
        deny all;
    }

    access_log off;
}

    fastcgi.conf配置:
    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 REQUEST_SCHEME $scheme;
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;

以前的

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";

开放目录访问权限(因为根目录设置到public下导致框架访问上级目录权限不够)

fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/wwwroot/:/tmp/:/proc/";

php.ini打开cgi.fix_pathinfo方便nginx解析路径

cgi.fix_pathinfo = 1

配置好之后重启Nginx和PHP-FPM

service nginx restart

service php-fpm restart

重启成功后你就可以这样访问:

domain/module/controller/action?params=value

以上是关于thinkphp5.0 +nginx在contos7下配置访问的主要内容,如果未能解决你的问题,请参考以下文章

关于ThinkPHP5.0的渲染模板输出

thinkphp5.0 与thinkphp5.1 db()函数的区别

thinkphp5.0.7 &===composer更新===& thinkphp5.0.9 debug “controller not found”(示例代码

thinkphp5.0独立配置

ThinkPHP5.0连接数据库的配置

ThinkPHP5.0---URL访问