webman-admin部署的问题

chao

问题描述

https://www.workerman.net/doc/webman/others/nginx-proxy.html
按照webman这里进行部署访问前台是没有问题的,但是访问admin就会出现静态资源404的问题。

/app/admin/component/pear/css/pear.css net::ERR_ABORTED 404 (Not Found)
/app/admin/component/layui/layui.js?v=2.8.12 net::ERR_ABORTED 404 (Not Found)

使用下面的配置访问都正常,但是会暴露项目的文件,项目几乎所有文件都能被下载。

location ^~ / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      if (!-f $request_filename){
          proxy_pass http://webman;
      }
}

按照webman系统能够自动把admin插件的静态资源代理过去的呀,插件里配置了public_path的。

return [
    'debug' => true,
    'controller_suffix' => 'Controller',
    'controller_reuse' => false,
    'public_path' => base_path('plugin' . DIRECTORY_SEPARATOR. 'admin' . DIRECTORY_SEPARATOR . 'public'),
    'plugin_market_host' => 'https://www.workerman.net',
    'version' => '0.6.33',
];

请问要如何正确的配置呢?

185 2 0
2个回答

魔鬼

设置了运行目录为public之后,也就public目录下面的文件可以访问,包括admin/public目录
其它文件是没法访问的,如果可以,那得检查一下nginx的配置
你说的暴露项目的文件是暴露了哪些文件?

  • chao 7天前

    我也很奇怪这点,配置是宝塔默认的项目配置,加了webman的代理。
    使用location ^~ / 这种方式代理就会导致项目目录的文件能被下载,比如.env,start.php等。非常不安全,所以才来问呀。

damao

https://www.workerman.net/doc/webman/others/nginx-proxy.html
按照文档

 # 拒绝访问所有以 .php 结尾的文件
  location ~ \.php$ {
      return 404;
  }

  # 允许访问 .well-known 目录
  location ~ ^/\.well-known/ {
    allow all;
  }

  # 拒绝访问所有以 . 开头的文件或目录
  location ~ /\. {
      return 404;
  }

上面这些配置决定了访问 .php 文件和访问 .env 文件都会404。
如果你能访问到,说明你没加这些配置。

  # 注意,这里一定是webman下的public目录,不能是webman根目录
  root /your/webman/public;

文档强调 root配置到 public 目录,public下不会有 start.php 和 .env ,如果你能访问到,说明这里也没配置对。

大家都没问题,你有问题,所以应该是你没按照文档配置导致的。

  • chao 6天前

    我现在的解决方案其实也差不多吧

        listen 80;
        listen 443 ssl;
        listen 443 quic;
        http2 on;
        server_name site;
        index index.php index.html index.htm default.php default.htm default.html;
        root /www/wwwroot/[sitedir]/public;
    
        # location ~ \.php$ {
        #   return 404;
        # }
    
        location ~ \.php$ {
          deny all;
        }
        location /.env {
            deny all;
            return 404;
        }
        location /.user.ini {
            deny all;
            return 404;
        }
    
        location /.git/ {
          deny all;
          return 404;
        }

    手动配置哪些不能访问。

🔝