s07q 发表于 2019-3-4 12:42:03

nginx二级目录访问后续问题PHP执行直接下载文件

本帖最后由 s07q 于 2019-3-4 19:36 编辑

之前问过宝塔nginx二级目录访问的事情,现在已经解决了,如下:
[*]location /software
[*]      {
[*]      alias /www/wwwroot/www_test_com/software;
[*]      autoindex on;
[*]      autoindex_exact_size off;
[*]      autoindex_localtime on;
[*]      charset utf-8,gbk;
[*]      }复制代码
可以直接打开目录列表文件

想着之前xiaoz大佬的Zdir目录列表程序不错,就想拿来用下,发现二级目录无法访问index.php文件,index.html可以直接访问
配置改为

[*]   location/software
[*]   {
[*]   alias /www/wwwroot/www_test_com/software;
[*]   index index.php index.html index.htm;
[*]    }复制代码

这样写index.html可以解析执行,但是index.php无法执行报错404
查了很多资料都没搞定,无奈厚脸皮问问MJJ如何配置



1.gif


乌龙了,还是报错404

[*]server
[*]{
[*]    listen 80;
[*]    server_name www.test.com test.com;
[*]    index index.php index.html index.htm default.php default.htm default.html;
[*]    root /www/wwwroot/www_test_com;
[*]   
[*]    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
[*]    #error_page 404/404.html;
[*]    #SSL-END
[*]   
[*]    #ERROR-PAGE-START错误页配置,可以注释、删除或修改
[*]    error_page 404 /404.html;
[*]    error_page 502 /502.html;
[*]    #ERROR-PAGE-END
[*]   
[*]    #PHP-INFO-STARTPHP引用配置,可以注释或修改
[*]    include enable-php-72.conf;
[*]    #PHP-INFO-END
[*]   
[*]    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
[*]    include /www/server/panel/vhost/rewrite/www.test.com.conf;
[*]    #REWRITE-END
[*] #============================================
[*] #允许访问software文件
[*]   location ^~ /software
[*]   {
[*]      index index.php index.html index.htm;
[*]      alias /www/wwwroot/www_test_com/software;
[*]      autoindex on;
[*]      autoindex_exact_size off;
[*]      autoindex_localtime on;
[*]      charset utf-8,gbk;
[*]    }   
[*]
[*]
[*] #============================================
[*]
[*]    #禁止访问的文件或目录
[*]    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
[*]    {
[*]      return 404;
[*]    }
[*]      
[*]    #一键申请SSL证书验证目录相关设置
[*]    location ~ \.well-known{
[*]      allow all;
[*]    }
[*]   
[*]    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
[*]    {
[*]      expires      30d;
[*]      error_log off;
[*]      access_log /dev/null;
[*]    }
[*]   
[*]    location ~ .*\.(js|css)?$
[*]    {
[*]      expires      12h;
[*]      error_log off;
[*]      access_log /dev/null;
[*]    }
[*]    access_log/www/wwwlogs/www.test.com.log;
[*]    error_log/www/wwwlogs/www.test.com.error.log;
[*]}复制代码

aRNoLD 发表于 2019-3-4 13:58:02

这些代码写的也太不规范了,花括号彼此都不一致。

nginx的autoindex完全可以换成fancyindex,比它这个强。

location block里面不用加utf8的配置,况且你还是写了两个。这个配置写在http block里,写一遍对所有的都适用了,反正现在编码utf8能够显示适用中文什么gbk的、拉丁的。

要想php能读,就不要在多重目录的情况下用死的路径,用~波浪号这类,适用到的路径一般会更多

qytang 发表于 2019-3-4 12:46:35

没配置php-fpm?fastcgi ?

s07q 发表于 2019-3-4 12:48:45


qytang 发表于 2019-3-4 12:46

没配置php-fpm?fastcgi ?
根本目录可以直接访问,二级目录需要重新配置么?
以前一直用apache没这些问题,nginx第一次用

hkwu 发表于 2019-3-4 12:46:00

惨案
022.gif

s07q 发表于 2019-3-4 14:02:22


aRNoLD 发表于 2019-3-4 13:58

这些代码写的也太不规范了,花括号彼此都不一致。

nginx的autoindex完全可以换成fancyindex,比它这个强。 ...
配置utf8是为了中文显示不乱码
另外,大佬格式就不要挑剔了,能运行是主要任务
页: [1]
查看完整版本: nginx二级目录访问后续问题PHP执行直接下载文件