本文翻译自:Make XAMPP/Apache serve file outside of htdocs [closed]

Is it possible to configure xampp to serve up a file outside of the htdocs directory? 是否可以配置xampp来提供htdocs目录之外的文件?

For instance, say I have a file located as follows: 例如,假设我有一个文件如下:

C:\\projects\\transitCalculator\\trunk\\TransitCalculator.php

and my xampp files are normally served out from: 我的xampp文件通常来自:

C:\\xampp\\htdocs\\

(because that's the default configuration) Is there some way to make Apache recognize and serve up my TransitCalculator.php file without moving it under htdocs ? (因为这是默认配置)是否有一些方法可以让Apache识别并提供我的TransitCalculator.php文件,而无需在htdocs下移动它? Preferably I'd like Apache to serve up/have access to the entire contents of the projects directory, and I don't want to move the projects directory under htdocs . 我希望Apache能够提供/访问项目目录的全部内容,我不想在htdocs下移动项目目录。

edit: edited to add Apache to the question title to make Q/A more "searchable" 编辑:编辑将Apache添加到问题标题,使Q / A更“可搜索”


#1楼

参考:https://stackoom.com/question/Mi/在Htdocs之外创建XAMPP-Apache服务文件-关闭


#2楼

You can set Apache to serve pages from anywhere with any restrictions but it's normally distributed in a more secure form. 您可以将Apache设置为从任何地方提供任何限制的页面,但它通常以更安全的形式分发。

Editing your apache files (http.conf is one of the more common names) will allow you to set any folder so it appears in your webroot. 编辑您的apache文件(http.conf是更常见的名称之一)将允许您设置任何文件夹,使其显示在您的webroot中。

EDIT: 编辑:

alias myapp c:\\myapp\\ 别名myapp c:\\ myapp \\

I've edited my answer to include the format for creating an alias in the http.conf file which is sort of like a shortcut in windows or a symlink under un*x where Apache 'pretends' a folder is in the webroot. 我已经编辑了我的答案,包括在http.conf文件中创建别名的格式,这有点像windows中的快捷方式或un * x下的符号链接,其中Apache'假装'文件夹在webroot中。 This is probably going to be more useful to you in the long term. 从长远来看,这对你来说可能更有用。


#3楼

You can relocate it by editing the DocumentRoot setting in XAMPP\\apache\\conf\\httpd.conf. 您可以通过编辑XAMPP \\ apache \\ conf \\ httpd.conf中的DocumentRoot设置来重定位它。

It should currently be: 它目前应该是:

C:/xampp/htdocs C:/ XAMPP / htdocs中

Change it to: 将其更改为:

C:/projects/transitCalculator/trunk C:/项目/ transitCalculator /行李箱


#4楼

Ok, per pix0r 's, Sparks ' and Dave 's answers it looks like there are three ways to do this: 好吧,根据pix0r , Sparks和Dave的回答看起来有三种方法可以做到这一点:


Virtual Hosts 虚拟主机

  1. Open C:\\xampp\\apache\\conf\\extra\\httpd-vhosts.conf. 打开C:\\ xampp \\ apache \\ conf \\ extra \\ httpd-vhosts.conf。
  2. Un-comment ~line 19 ( NameVirtualHost *:80 ). 取消评论〜第19行( NameVirtualHost *:80 )。
  3. Add your virtual host (~line 36): 添加虚拟主机(〜第36行):

     <VirtualHost *:80> DocumentRoot C:\\Projects\\transitCalculator\\trunk ServerName transitcalculator.localhost <Directory C:\\Projects\\transitCalculator\\trunk> Order allow,deny Allow from all </Directory> </VirtualHost> 
  4. Open your hosts file (C:\\Windows\\System32\\drivers\\etc\\hosts). 打开主机文件(C:\\ Windows \\ System32 \\ drivers \\ etc \\ hosts)。

  5. Add

     127.0.0.1 transitcalculator.localhost #transitCalculator 

    to the end of the file (before the Spybot - Search & Destroy stuff if you have that installed). 到文件的末尾(在Spybot之前 - 如果安装了那么搜索和销毁东西)。

  6. Save (You might have to save it to the desktop, change the permissions on the old hosts file (right click > properties), and copy the new one into the directory over the old one (or rename the old one) if you are using Vista and have trouble). 保存(您可能必须将其保存到桌面,更改旧主机文件的权限(右键单击>属性),如果您正在使用,则将新的权限复制到旧目录上(或重命名旧主机目录) Vista并且有麻烦)。
  7. Restart Apache. 重启Apache。

Now you can access that directory by browsing to http://transitcalculator.localhost/ . 现在,您可以通过浏览到http://transitcalculator.localhost/来访问该目录。


Make an Alias 制作别名

  1. Starting ~line 200 of your http.conf file, copy everything between <Directory "C:/xampp/htdocs"> and </Directory> (~line 232) and paste it immediately below with C:/xampp/htdocs replaced with your desired directory (in this case C:/Projects ) to give your server the correct permissions for the new directory. http.conf文件的第200行开始,复制<Directory "C:/xampp/htdocs"></Directory> (〜第232行)之间的所有内容并将其粘贴到下面,并将C:/xampp/htdocs替换为您的所需目录(在本例中为C:/Projects )为您的服务器提供新目录的正确权限。

  2. Find the <IfModule alias_module></IfModule> section (~line 300) and add 找到<IfModule alias_module></IfModule>部分(〜第300行)并添加

     Alias /transitCalculator "C:/Projects/transitCalculator/trunk" 

    (or whatever is relevant to your desires) below the Alias comment block, inside the module tags. (或与您的愿望相关的任何内容)在模块标签内的Alias注释块下方。


Change your document root 更改文档根目录

  1. Edit ~line 176 in C:\\xampp\\apache\\conf\\httpd.conf; 编辑C:\\ xampp \\ apache \\ conf \\ httpd.conf中的〜第176行; change DocumentRoot "C:/xampp/htdocs" to #DocumentRoot "C:/Projects" (or whatever you want). DocumentRoot "C:/xampp/htdocs"更改为#DocumentRoot "C:/Projects" (或任何您想要的)。

  2. Edit ~line 203 to match your new location (in this case C:/Projects ). 编辑〜第203行以匹配您的新位置(在本例中为C:/Projects )。


Notes: 笔记:

  • You have to use forward slashes "/" instead of back slashes "\\". 你必须使用正斜杠“/”而不是反斜杠“\\”。
  • Don't include the trailing "/" at the end. 不要在末尾包含尾部“/”。
  • restart your server . 重启你的服务器

#5楼

A VirtualHost would also work for this and may work better for you as you can host several projects without the need for subdirectories. VirtualHost也可以为此工作,并且可以更好地为您工作,因为您可以托管多个项目而无需子目录。 Here's how you do it: 这是你如何做到的:

httpd.conf (or extra\\httpd-vhosts.conf relative to httpd.conf. Trailing slashes "\\" might cause it not to work): httpd.conf(或相对于httpd.conf的额外\\ httpd-vhosts.conf。尾随斜杠“\\”可能导致它无法工作):

NameVirtualHost *:80
# ...
<VirtualHost *:80>  DocumentRoot C:\projects\transitCalculator\trunk\ServerName transitcalculator.localhost<Directory C:\projects\transitCalculator\trunk\>  Order allow,deny  Allow from all  </Directory>
</VirtualHost>

HOSTS file (c:\\windows\\system32\\drivers\\etc\\hosts usually): HOSTS文件(通常是c:\\ windows \\ system32 \\ drivers \\ etc \\ hosts):

# localhost entries
127.0.0.1 localhost transitcalculator.localhost

Now restart XAMPP and you should be able to access http://transitcalculator.localhost/ and it will map straight to that directory. 现在重新启动XAMPP,您应该能够访问http://transitcalculator.localhost/ ,它将直接映射到该目录。

This can be helpful if you're trying to replicate a production environment where you're developing a site that will sit on the root of a domain name. 如果您尝试复制正在开发将位于域名根目录的网站的生产环境,这可能会有所帮助。 You can, for example, point to files with absolute paths that will carry over to the server: 例如,您可以指向具有绝对路径的文件,这些路径将转移到服务器:

<img src="/images/logo.png" alt="My Logo" />

whereas in an environment using aliases or subdirectories, you'd need keep track of exactly where the "images" directory was relative to the current file. 而在使用别名或子目录的环境中,您需要跟踪“images”目录相对于当前文件的确切位置。


#6楼

Solution to allow Apache 2 to host websites outside of htdocs: 允许Apache 2托管htdocs之外的网站的解决方案:

Underneath the "DocumentRoot" directive in httpd.conf, you should see a directory block. 在httpd.conf中的“DocumentRoot”指令下面,您应该看到一个目录块。 Replace this directory block with: 将此目录块替换为:

<Directory />Options FollowSymLinksAllowOverride AllAllow from all
</Directory>

REMEMBER NOT TO USE THIS CONFIGURATION IN A REAL ENVIRONMENT 请记住,不要在真实环境中使用此配置

在Htdocs之外创建XAMPP / Apache服务文件[关闭]相关推荐

  1. Linux初入19 Apache服务

    文章目录 1 什么叫Apache服务,如何启动 1.1Apache 1.2启动Apache 1.3 了解主要的文件内容. 1.4.了解apache服务的配置文件 2 Selinux子系统 2.1 了解 ...

  2. Apache服务安全加固及Apache优化

    转载来源 :https://help.aliyun.com/knowledge_detail/52981.html 一.账号设置 以专门的用户帐号和用户组运行 Apache 服务. 1.根据需要,为 ...

  3. CentOS 7 Apache服务的安装与配置(转)

    https://blog.51cto.com/13525470/2070375 一.Apache简介 Apache 是一个知名的开源Web服务器. 早期的Apache服务器由Apache Group来 ...

  4. Linux之apache服务搭建以及浅析web安全

    WEB服务器的架设,在linux有一个很著名的架构叫lamp:linux+apache+mysql+php,就知道apache的分量了.   在搭建apache服务钱需要做DNS服务器 DNS的搭建h ...

  5. apache服务讲解

    apache服务讲解 1.基础认识 **HTML语言:**超文本标记语言,使用html语言编写的文本叫超本,"超文本"就是指页面内可以包含图片.链接,甚至音乐.程序等非文字元素. ...

  6. 配置Apache服务

    Apache简介(Web服务器) Apache HTTP Server是广泛应用的Web应用系统之一,要运用好它,必须先了解它的特点及其编译安装过程. Apache HTTP Server 是开源软件 ...

  7. Observability:从零开始创建 Java 微服务并监控它 (一)

    在本教程中,你将学习如何使用 Elastic 可观察性监控 Java 应用程序:日志.基础设施指标.APM 和正常运行时间.通过本教程,你将学到: 创建示例 Java 应用程序. 使用 Filebea ...

  8. 《Apache服务》

    WEB服务 http协议简介: HTTP协议,全称HyperText Transfer Protocol,中文名称超文本传输协议,是互联网上应用最为广泛的一种网络协议.所有WWW都必须遵守这个标准.设 ...

  9. 使用Apache服务部署静态网站

    10.1 网站服务程序 1970年,作为互联网前身的ARPANET(阿帕网)已初具雏形,并开始向非军用部门开放,许多大学和商业部门开始接入.虽然彼时阿帕网的规模(只有4台主机联网运行)还不如现在的局域 ...

最新文章

  1. golang atomic 32位机器问题
  2. ImageMagick之PDF转换成图片(image)
  3. 记录转化为有层次结构的树状列表的通用算法
  4. image_thumb1
  5. 湖北民族学院c语言试卷,C实验参考答案(湖北民族学院计算机c语言课后习题答案).doc...
  6. 云炬Android开发笔记 2-2 Android studio项目上传到Github及无法连接Github的问题处理
  7. How to resolve Unable to load groups error message
  8. cjmx:JConsole的命令行版本
  9. cookie和session的区别和用法
  10. vs2010常见错误记录
  11. css布局模型详细介绍
  12. NOIP2013 D1T3 货车运输 倍增LCA OR 并查集按秩合并
  13. 测试python安装成功_Python在Windows上安装配置测试
  14. [转载] python中随机数生成函数_python中seed随机函数如何生成随机数?
  15. EOJ 262 润清的烦恼
  16. 【js特效】一款不错的flash视频播放器
  17. 李想:“做正确的事,不做容易的事”
  18. 感冒会引发腺样体肥大吗?
  19. AutoCad vba宏 用于线路设计方面简化工作量 明白的拿走
  20. Pytorch基础知识(7)单目标检测

热门文章

  1. [李景山php]每天TP5-20161205|Loader.php-3
  2. 从ajax获取的数据无法通过Jquery选择器来调用事件
  3. C#中Delegate和Event以及它们的区别
  4. 《计算机操作系统》学习笔记(三)---存储器管理
  5. JIRA OutOfMemoryErrors
  6. 2018-2019-2 20175215 实验五《网络编程与安全》实验报告
  7. 前端Js框架汇总【转】
  8. ASP.NET 文件操作类
  9. 【腾讯云的1001种玩法】 Laravel 整合微视频上传管理能力,轻松打造视频App后台...
  10. SCWS中文分词,功能函数实例应用