我目前在我的应用程序的配置文件中有以下内容:
define('DOCROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
define('WEBROOT', 'http://localhost/samples/');
Run Code Online (Sandbox Code Playgroud)
第一行完美无缺.我可以在任何地方包含配置文件,然后DOCROOT按预期使用常量.
第二行也适用,但它是硬编码的,这意味着当我将此文件上传到我的网络服务器时,它将是错误的.它应该是http://samples.example.com.是否有一种好方法可以防止这种硬编码?我觉得我必须在某个地方硬编码,在那种情况下,我可以逃脱的是什么和多少?
我有一个指向文档根的lighttpd-Setup /var/www.但是,我希望URL other/指向/some/other/dir.我正在使用以下配置:
$HTTP["url"] =~ "^/other($|/)" {
server.document-root = "/some/other/dir"
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我访问'http:// myhost/other',则lighttpd会尝试访问/some/other/dir/other而不是仅仅访问/some/other/dir.有可能以某种方式剥离/other但保留任何进一步的URL段吗?所以,例如,http://myhost/other/sub/foo.txt应该指出/some/other/dir/sub/foo.txt.
<html>在jQuery中获取根文档节点(元素)的最佳方法(性能方面)是什么?我可以想到几种可能有效或无效的方法:
$("html")
$(document.documentElement)
$(document) (?)
$.root (?)
$.document (?)
我需要一些关于网站"root"网址和目录的概念和术语的帮助.
是否有可能确定网站的根目录,或者这是一个随意的想法,只能建立实际服务器的根目录?
假设我正在编写一个PHP插件,该插件将被不同位置的不同网站使用,但需要确定网站的基本目录是什么.使用PHP,我将始终能够确定DOCUMENT_ROOT和SERVER_NAME,即服务器(或虚拟服务器)的绝对URL和绝对目录路径.但我不知道网站本身是"安装"在根目录还是子目录中.如果网站在子目录中,我需要用户明确设置"子路径"变量.正确?
我正在尝试学习一种更好的方法来回到根目录.我听说使用$ _SERVER并不是最安全的方法.我想知道是否有更好的方法.所以我可以在url example.com/exp/my.php上得到类似的东西
这就是我得到的.
include ($_SERVER['DOCUMENT_ROOT'].'/cpages/cmain/func/init.php');
include($_SERVER['DOCUMENT_ROOT'].'/cpages/toppart.php');
include($_SERVER['DOCUMENT_ROOT'].'/cpages/boxes/image.php');
include($_SERVER['DOCUMENT_ROOT'].'/cpages/bottonpart.php');
Run Code Online (Sandbox Code Playgroud)
我改成了
define ('DOCUMENT_ROOT', dirname(__FILE__));
include (DOCUMENT_ROOT.'/cpages/cmain/func/init.php');
include(DOCUMENT_ROOT.'/cpages/toppart.php');
include(DOCUMENT_ROOT.'/cpages/boxes/image.php');
include(DOCUMENT_ROOT.'/cpages/bottonpart.php');
Run Code Online (Sandbox Code Playgroud)
但现在它给了我一个错误
Warning: include(C:\xampp\htdocs\backbone\image/cpages/cmain/func/init.php)
Run Code Online (Sandbox Code Playgroud)
并($_SERVER['DOCUMENT_ROOT']没有告诉我,错误是他们修复它的方法吗?
我已经安装了apache 2.2 in centos 6.当apache文件夹位于默认位置时,一切正常/var/www/html.然后我在我的用户主文件夹中配置了一个虚拟主机.之后,Forbidden You don't have permission error当我试图进入localhost或127.0.0.1离开浏览器时,apache开始显示.
这是我在httpd.conf中使用的代码
<VirtualHost *:80>
DocumentRoot "/home/anjan/workspace/mfs"
ServerName anjan-centOS
<Directory "/home/anjan/workspace/mfs">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
我也SElinux像一些文章中提到的那样残疾但是徒劳无功.如果有人能帮助我,我将不胜感激.
我在CentOS 6.4上安装了apache并配置了我的虚拟主机.
但是,当我重新启动apache(使用此命令:sudo service httpd restart)时,它警告我"警告:DocumentRoot [/ var/www/vhosts]不存在".我已经检查了目录/ var/www/vhosts,它已经创建了,权限是0777.我做错了什么?任何帮助请...
- >这是我的虚拟主机配置.
DocumentRoot /var/www/vhosts
ServerName trien.cba
ServerAlias trien.cba
ErrorLog /var/log/httpd/trien.cba.error.log
CustomLog /var/log/httpd/trien.cba.access.log common
AllowOverride All
Order allow,deny
Allow from all
Options -Indexes
Run Code Online (Sandbox Code Playgroud)
....
- >这是警告:
[root@test-cba ~]#sudo service httpd restart
Stopping httpd: [ OK ]
Starting httpd: Warning: DocumentRoot [/var/www/vhosts] does not exist
Warning: DocumentRoot [/var/www/vhosts] does not exist
Run Code Online (Sandbox Code Playgroud) 如果我通过"www.mysite.com/img/"访问我的网站
我会看到以下内容:
父目录......
文件夹1
文件夹2
文件1
文件2
等等..
但是什么是阻止人们访问我的网站文件夹和文件结构的最佳方法?
虽然仍然让人们查看例如实际网站上的图像
我也想隐藏例如www.mysite.com/functions/我有我的php函数文件.
检查谷歌向我展示了很多方法,
但最好和最安全的方法是什么?
提前致谢!
在PHP中,您可以通过以下方式获取文档根目录:$_SERVER['DOCUMENT_ROOT'].EJ:
PHP
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$path = '/example/directory/';
$file = 'some-file.html';
include( $root . $path . $file );
...etc
?>
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得$_SERVER['DOCUMENT_ROOT']jQuery/JavaScript 的价值?
jQuery的
//Example:
var root = ????;
var path = 'example/directory/';
var file = 'some-file.txt';
$("#example").load( root + path + file );
Run Code Online (Sandbox Code Playgroud)
注意:每当我处理目录时,在HTML页面上,"BASE"目录将成为当前文件的目录.Ej , www.ejample.com/documents/examples/this-ex.html. 如果我只是打电话$("#example").load( path + file )请求documents/examples/ + example/directory.就像我说的,这不是关于服务器端的问题.是关于获得正确(和自动)目录位置
/var/www/html我试图找到我的 Apache 配置中仍然存在对 的引用。当我运行时,apache2ctl -S它显示Main DocumentRoot: "/var/www/html",但我的虚拟主机或主 Apache 配置文件都没有指向该目录。
我尝试使用搜索所有配置文件grep -r "var/www/html" /etc/apache2/,但它什么也没返回。
我的文件中没有<Directory>该路径的条目/etc/apache2/apache2.conf(有一个/var/www,我在其下存储虚拟主机)。
这种配置怪癖困扰着我的强迫症,但我也经常在 Apache 错误日志中看到这些条目:
[Fri Jun 28 18:19:53.424619 2019] [autoindex:error] [pid 22665]
[client 209.222.82.167:47376] AH01276: Cannot serve directory
/var/www/html/: No matching DirectoryIndex
(default.php,index.php,index.html,index.htm) found, and server-generated
directory index forbidden by Options directive
Run Code Online (Sandbox Code Playgroud)
Apache 如何决定主文档根是什么,以及如何更改它?
编辑:
对于我的可用站点/已启用站点,我有四个文件:000-default.conf、000-default-le-ssl.conf、000-www-default.conf和000-www-default-le-ssl.conf。这000-default.conf是 certbot 设置的重定向,指向 https 站点,并且没有 DocumentRoot 指令。与ServerName000-www-default.conf相同 …