1. 程式人生 > >thinkphp5.0 +nginx在contos7下配置訪問

thinkphp5.0 +nginx在contos7下配置訪問

pathinfo code ase cgi配置 開放 contos ram software info

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下配置訪問