@phpstudy中使用nginx配置thinkphp5
最近用nginx中配置thinkphp5遇到一些问题,现在将配置过程记录下来
第一步:在C:\Windows\System32\drivers\etc下的host文件中配置虚拟域名,如:127.0.0.1 www.ysh.com
第二步:在phpStudy程序文件下找到nginx的虚拟主机配置文件,如: D:\phpStudy\PHPTutorial\nginx\conf\vhosts.conf,将下面代码复制到vhosts.conf文件中:
server {
listen 80; #这里的端口号是80,不要改动#
server_name www.ysh.com;
root "D:/phpStudy/PHPTutorial/WWW/tp5/public";
location / {
index admin.php index.html index.htm index.php admin.php;
#autoindex on;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=/$1 last; #这里指定入口文件,index.php入口文件,
}
if (!-e $request_filename){
rewrite ^(.*)$ /admin.php?s=/$1 last; #如果项目中是多入口,则增加这里的代码,admin.php是你的入口文件
}
}
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;
}
}
提示:
#root后是你项目所在的路径,因为thinkphp5的入口文件在public下,所以指定到public
#root后的路径中不能使用 \ ,一定要将 \ 改成 / ,网上查了资料,好像是nginx中不会转义 \ ,总之记得改过来;
第三步:重启phpStudy,然后再浏览器中输入虚拟域名,如:www.ysh.com
最后这是我个人配置中总结的一些步骤,存在问题请指正,希望能够帮到需要的人