zoukankan      html  css  js  c++  java
  • 关于Thinkphp访问不正常的问题

    最近遇见了个蹩脚的问题,我放在服务器的项目(thinkphp框架)只能访问默认路径内容,不管你url怎么写的,他就访问默认那个文件..

    对于有强迫症的我来说实在是欺人太甚!!!

    于是乎我就抓耳挠腮了...

    说一下我的服务,php7.0 +nginx+ mysql +Linux(ubuntu)

    由于不知问题出在哪里,所以排查起来很费劲

    首先,把项目放在本地和服务器分别试了一下,本地没毛病,线上全毛病,额,这说明项目木得问题

    然后,设置一下文件权限,有读写权限即可,这个命令就不用说了吧,可以度

    接下来还不行,那就是配置的原因了

    nginx配置文件

    /etc/nginx/conf.d/的conf文件

    内容如下:

    server {
        listen       80;
        server_name  wp.***.com;
        root /workspace/home;
        index  index.html index.htm index.php;
        error_page  404              /404.html;
        location = /404.html {
            return 404 'Sorry, File not Found!';
        }
        error_page  500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html; 
        }
        location / {
            try_files $uri @rewrite;
        }
        location @rewrite {
            set $static 0;
            if  ($uri ~ .(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css.map|min.map)$) {
                set $static 1;
            }
            if ($static = 0) {
                rewrite ^/(.*)$ /index.php?s=/$1;
            }
        }
        location ~ /Uploads/.*.php$ {
            deny all;
        }
        location ~ .php/ {
           if ($request_uri ~ ^(.+.php)(/.+?)($|?)) { }
           fastcgi_pass 127.0.0.1:9000;
           include fastcgi_params;
           fastcgi_param SCRIPT_NAME     $1;
           fastcgi_param PATH_INFO       $2;
           fastcgi_param SCRIPT_FILENAME $document_root$1;
        }
        location ~ .php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        location ~ /.ht {
            deny  all;
        }
    }

    这个配置文件挺全的,完美支持普通,兼容,pathinfo,rewrite4种url模式,别怪我没提醒你收藏哦. 常见的静态文件404时也不会再去跑一遍fastcgi浪费资源。

    恩,完美解决。哈哈哈哈哈哈

  • 相关阅读:
    Google服务
    Duwamish深入剖析配置篇
    Duwamish Online SQL XML 分类浏览
    数据库操作类
    搜索引擎Google的小秘密
    微软.NET经典架构例程Duwamish 7.0分析
    一个ASP.NET中使用的MessageBox类
    轻松解决页面回传后页面滚动到顶端
    Duwamish 7 初探——数据流程
    使用ADO.NET的最佳实践
  • 原文地址:https://www.cnblogs.com/guaiyouyisi/p/7905171.html
Copyright © 2011-2022 走看看