thinkphp5和nginx不得不说的故事

由于之前学习用的都是apsche,所以对ngnix一窍不通,在这里写给正在学习的同行,希望可以帮助到你们:

如果你不会用apache部署tp5的可以查看我之前发布的文章,里面有提到

phpstudy

参考:https://blog.csdn.net/qq_33862644/article/details/78174041

你切换ngnix之后,你只能访问tp5的首页,这时候点击其他事不能访问的到的,会报403错误,是因为你的pathinfo没有设置,这时候就需要伪静态了。

在“打开配置文件”中找到vhsts.conf,打开,然后配置伪静态的代码:

server {
        listen       80;
        server_name  www.bicktp.com bicktp.com;
        root   "E:wampwwwickpublic";
        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;
        }
}

我有写注释的,你自己看着写吧。

 

然后在linux系统上部署也是一样的。

参考:https://www.cnblogs.com/fangziffff123/p/7588782.html

我用最原始的方法自己写不知道为什么运行不了,可能是某些代码缺失了吧,所以我是了第三方工具帮我配置->宝塔面板

 那个配置文件基本不用谢,只写伪静态就可以了!!!

你们好,还是我,今天使用了thinkphp5.1,搭建环境是nginx,然后发现现在新版本的tp框架好像不用写伪静态都可以跑了,只是要写多一个index.php才能跑起来,这个让我有点不爽,很不雅观的好不好,万一这样让外人看见了,他们想上我什么办,于是我就去查了一下资料:

来源:

https://xieye.iteye.com/blog/2436835

主要加上try_files 指令就好,不多说,上代码:

server {
        listen       80;
        server_name  layton.com;
        root   "F:/phpstudy_pro/WWW/layton/public";
        location / {
            try_files  $uri  /index.php$uri$is_args$args; 
            

            index index.php index.html /error/index.html;
            error_page  400  /error/400.html;
            error_page  403  /error/403.html;
            error_page  404  /error/404.html;
            error_page  500  /error/500.html;
            error_page  501  /error/501.html;
            error_page  502  /error/502.html;
            error_page  503  /error/503.html;
            error_page  504  /error/504.html;
            error_page  505  /error/505.html;
            error_page  506  /error/506.html;
            error_page  507  /error/507.html;
            error_page  508  /error/508.html;
            error_page  509  /error/509.html;
            error_page  510  /error/510.html;
            autoindex  off;
        }
        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;
        }
}
原文地址:https://www.cnblogs.com/laijinquan/p/9208166.html