nginx如何实现thinkphp去掉index.php访问?

我试过http://www.thinkphp.cn/topic/...,实际访问报404

nginx 1.10.3
php-fpm
php7.1
Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-117-generic x86_64)

这是环境,
下面是我apache中关于php-fpm的相关配置

index index.html index.htm index.php default.html default.php index.nginx-debian.html;

# if (!-e $request_filename)
# {
#     #地址作为将参数rewrite到index.php上。
#     rewrite ^/(.*)$ /index.php/$1;
#     #若是子目录则使用下面这句,将subdir改成目录名称即可。
#     #rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
# }

# location ~ .php
# {
#         #原有代码
#         
#         #定义变量 $path_info ,用于存放pathinfo信息
#         set $path_info "";
#         #定义变量 $real_script_name,用于存放真实地址
#         set $real_script_name $fastcgi_script_name;
#         #如果地址与引号内的正则表达式匹配
#         if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
#                 #将文件地址赋值给变量 $real_script_name
#                 set $real_script_name $1;
#                 #将文件地址后的参数赋值给变量 $path_info
#                 set $path_info $2;
#         }
#         #配置fastcgi的一些参数
#         fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
#         fastcgi_param SCRIPT_NAME $real_script_name;
#         fastcgi_param PATH_INFO $path_info;
# }

location / {

    # if (!-e $request_filename) {
    #     rewrite  ^/(.*)$  /index.php/$1  last;
    #     break;
    # }

    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
}

location ~ ^(.+\.php)(.*)$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;

    include fastcgi_params;

    fastcgi_split_path_info       ^(.+\.php)(.*)$;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
}

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
    deny all;
}

阅读 4.2k
1 个回答

server {    
    charset utf-8;    
    client_max_body_size 128M;    
    listen 80;    
    server_name tp5.local.test;    
    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;    
    }    
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题