Nginx配置thinkphp项目只能访问首页的问题

tp 是把自己当作主站来处理的,如果不想去修改配置文件,那么就要把 tp 项目设置成虚拟主机或把 tp 项目所在目录设置成虚拟目录
如果是 apache 就很简单,把 .htaccess 放在项目目录中就可以了,所以apache配置tp项目基本上不会出现这种问题,只有Nginx会出现访问所有链接却跳转到首页的问题。
修改nginx.conf配置如下
server {

    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    server_name xxxxx;
    root your path;
    index index.php index.html index.htm;

    location / {
         try_files $uri $uri/ /index.php$is_args$args;
         #访问路径的文件不存在则重写URL转交给ThinkPHP处理
                 if (!-e $request_filename) {
                    rewrite  ^/(.*)$  /index.php/$1  last;
                    break;
                 }
    }

    location ~ \.php {#此处php后面的$符号要去掉
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        #加载Nginx默认"服务器环境变量"配置
                include        fastcgi.conf;

                #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量
                set $fastcgi_script_name2 $fastcgi_script_name;
                if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
                    set $fastcgi_script_name2 $1;
                    set $path_info $2;
                }
                fastcgi_param   PATH_INFO $path_info;
                fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }
}

你可能感兴趣的:(Nginx配置thinkphp项目只能访问首页的问题)