phpstudy在nginx中配置thinkPHP伪静态步骤方法

2025-11-21 14:13:45

1、安装好PHPstudy后,切换环境为PHP+nginx,版本根据自己需要

phpstudy在nginx中配置thinkPHP伪静态步骤方法

2、在PHPstudy【其他选项菜单】中->打开配置文件->选择vhosts-ini(有的是vhosts-conf),用文本编辑器notepad打开

phpstudy在nginx中配置thinkPHP伪静态步骤方法

3、这里我们可以看到我们自己创建的网站配置(当然,没有创建网站的话者这里是没有配置内容的)

phpstudy在nginx中配置thinkPHP伪静态步骤方法

4、因为vhosts里面没有写入伪静态内容,所以我们访问本地thinkPHP的网站的话是访问不了的

5、这里我们加入thinkPHP的伪静态内容

phpstudy在nginx中配置thinkPHP伪静态步骤方法

6、内容如下:

# 伪静态配置

            if (!-e $request_filename) {

                rewrite  ^(.*)$  /index.php?s=$1  last;

                break;

            }

############

注意加入的位置不能错!!!!

7、如果未创建网站,可以直接复制下面内容到vhosts-ini中:

server {

        listen       80;

        server_name  www.b1.com b1.com;#填你第8步dns解析,配置的虚拟域名

        root   "D:\phpStudy\PHPTutorial\WWW\b1";#填你网站所在目录

        location / {

            index  index.html index.htm index.php;

            #autoindex  on;

######伪静态配置########

            if (!-e $request_filename) {

                rewrite  ^(.*)$  /index.php?s=$1  last;

                break;

            }

######伪静态配置########

        }

        location ~ \.php(.*)$ {

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            fastcgi_param  PATH_INFO  $fastcgi_path_info;

            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;

            include        fastcgi_params;

        }

}

8、DNS解析:在C:\Windows\System32\drivers\etc下打开hosts,加入你配置的域名解析到本地的代码 例如:

phpstudy在nginx中配置thinkPHP伪静态步骤方法

9、重启PHPstudy环境,再刷新页面,这时,我们就能看到本地的thinkPHP项目能访问了

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢