栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > zblog

PhpStudy在nginx下配置虚拟主机和伪静态

zblog 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PhpStudy在nginx下配置虚拟主机和伪静态

  1. 使用zblogPhp中的静态管理中心插件来伪静态,如图所示

server {
        listen        80;
        server_name  www.dailyflower.club dailyflower.club;
        root   "C:/phpstudy_pro/WWW/dailyflower";
        location / {
            index index.php index.html;
            include C:/phpstudy_pro/WWW/dailyflower/nginx.htaccess;
            autoindex  on;
			
	  #贴入它所推荐代码
if (-f $request_filename/index.html){
	rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
	rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
	rewrite (.*) /index.php;
}
			
        }

结果:出现index.html 页面,具体原因应该是以上代码的匹配规则的问题,Nginx Rewrite规则语法 参考如下
https://blog.csdn.net/u011598153/article/details/48181519

  1. 正确的解决方式: 换成如下代码就行了

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

 # 伪静态配置
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=$1  last;
                break;
            }

4.总算解决了伪静态的问题,记录一下

  1. 经测试:官方推荐的去掉前两个if后也是可以用的,应该是正则表达式的拦截
server {
        listen        80;
        server_name  www.dailyflower.club dailyflower.club;
        root   "C:/phpstudy_pro/WWW/dailyflower";
        location / {
            index index.php index.html;
            include C:/phpstudy_pro/WWW/dailyflower/nginx.htaccess;
            autoindex  on;
			
	  #只剩下第三个if
			if (!-f $request_filename){
				rewrite (.*) /index.php;
			}
        }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/834498.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号