
正文
关于Thinkphp访问不正常的问题
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
最近遇见了个蹩脚的问题,我放在服务器的项目(thinkphp框架)只能访问默认路径内容,不管你url怎么写的,他就访问默认那个文件..
对于有强迫症的我来说实在是欺人太甚!!!
于是乎我就抓耳挠腮了...
说一下我的服务,php7.0 +nginx+ mysql +Linux(ubuntu)
由于不知问题出在哪里,所以排查起来很费劲
首先,把项目放在本地和服务器分别试了一下,本地没毛病,线上全毛病,额,这说明项目木得问题
然后,设置一下文件权限,有读写权限即可,这个命令就不用说了吧,可以度
接下来还不行,那就是配置的原因了
nginx配置文件
/etc/nginx/conf.d/的conf文件
内容如下:
server {
listen ;
server_name wp.***.com;
root /workspace/home;
index index.html index.htm index.php;
error_page /.html;
location = /.html {
return 'Sorry, File not Found!';
}
error_page /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location / {
try_files $uri @rewrite;
}
location @rewrite {
set $static ;
if ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
set $static ;
}
if ($static = ) {
rewrite ^/(.*)$ /index.php?s=/$;
}
}
location ~ /Uploads/.*\.php$ {
deny all;
}
location ~ \.php/ {
if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }
fastcgi_pass 127.0.0.1:;
include fastcgi_params;
fastcgi_param SCRIPT_NAME $;
fastcgi_param PATH_INFO $;
fastcgi_param SCRIPT_FILENAME $document_root$;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
这个配置文件挺全的,完美支持普通,兼容,pathinfo,rewrite4种url模式,别怪我没提醒你收藏哦. 常见的静态文件404时也不会再去跑一遍fastcgi浪费资源。
恩,完美解决。哈哈哈哈哈哈







