如何找出网站代码所在的位置?

Raf*_*ael 28 ubuntu php apache-2.2

事实:

  • 有一个网站
  • 本网站可通过 www.example.org 访问
  • 有一个很可能保留网站的 EC2 实例
  • 服务器是Apache
  • 服务器操作系统是 Ubuntu
  • 我拥有对服务器的完全访问权限(和 sudo 权限)
  • 服务器是一团糟

问题是我不知道在哪里 - 简单地放置 - 找到加载的 index.html/index.php 。

我如何找出在哪里可以找到网站的 PHP 和 HTML 代码?有没有系统的方法来解决这个问题?

ALe*_*hha 53

首先,您应该检查服务器上托管了哪些网站

# apachectl -t -D DUMP_VHOSTS
Run Code Online (Sandbox Code Playgroud)

然后当你找到一个站点时,检查选项 DocumentRoot 的相应配置文件。例如

# apachectl -t -D DUMP_VHOSTS
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server 192.168.88.87 (/etc/httpd/conf.d/192.168.88.87.conf:1)
         port 80 namevhost 192.168.88.87 (/etc/httpd/conf.d/192.168.88.87.conf:1)
         port 80 namevhost gl-hooks.example.net (/etc/httpd/conf.d/hooks.conf:1)
                 alias example.net
                 alias www.example.net
Run Code Online (Sandbox Code Playgroud)

您想知道网站 example.net 所在的位置

# grep DocumentRoot /etc/httpd/conf.d/hooks.conf
    DocumentRoot /vhosts/gl-hooks.example.net/

# cd /vhosts/gl-hooks.example.net/
# ls -la
total 4484
drwxr-xr-x  6 apache apache    4096 Feb 10 11:59 .
drwxr-xr-x 14 root   root      4096 Feb 23 08:54 ..
-rw-r--r--  1 root   root      1078 Dec 19 09:31 favicon.ico
-rw-r--r--  1 apache apache     195 Dec 25 14:51 .htaccess
-rw-r--r--  1 apache apache      98 Dec  7 10:52 index.html
Run Code Online (Sandbox Code Playgroud)

还应该注意别名和重定向/重写

您还应该注意任何别名指令。例如使用以下设置

<VirtualHost *:80>
   ServerName example.net
   ServerAlias www.example.net
   ...
   DocumentRoot /vhosts/default/public_html/
   Alias /api/ /vhosts/default/public_api/
   ...
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

当您访问http://example.net/some.file.html - apache 将在 /vhosts/default/public_html/ 中查看文件,同时使用http://example.net/api/some.file .html文件将被查看 /vhosts/default/public_api/。

重写/重定向如何,尤其是程序化的(当重定向由某些 php 代码触发时),我认为没有简单的方法可以找到这种情况。

  • 还应该注意别名和重定向/重写。 (3认同)