由于查看根目录,文件未显示,但我想我指定了根目录!

发布于 2024-11-25 16:03:25 字数 815 浏览 4 评论 0原文

我在本地工作,并且总是将文件指定为 /files.jpg 或其他名称,这样服务器将始终知道查看根级别来查找文件。这样,如果我在子页面上,它就不会被阻塞。但本地文件不显示。我的文件结构是 ap​​ache2/htdocs/name_of_folder。 name_of_folder 是我的“根”。然后我修改我的虚拟主机文件,这样当我输入 localhost/name_of_folder 时,它将显示我的站点。我指定了 DocumentRoot,所以我想当我说 localhost/name_of_folder 正在文档根目录下工作时?

在 httpd-vhosts.conf 中,我将其设置为

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/opt/local/apache2/name_of_folder"
    ServerName localhost/name_of_folder
    ServerAlias www.localhost/name_of_folder
    ErrorLog "logs/name_of_folder_log"
    CustomLog "logs/name_of_folder_access_log" common
</VirtualHost>

我做错了什么?

I'm working locally and I always specify files as /files.jpg or whatnot so the server will always know to look at the root level to find the files. That way if I'm on a subpage it won't choke. But locally the files do not show up. My file structure is apache2/htdocs/name_of_folder. name_of_folder is my "root". I then modify my virtualhost file so when I enter localhost/name_of_folder it will show my site. I specify the DocumentRoot so I thought when I say localhost/name_of_folder that is working at the document root?

In httpd-vhosts.conf I have it set to

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/opt/local/apache2/name_of_folder"
    ServerName localhost/name_of_folder
    ServerAlias www.localhost/name_of_folder
    ErrorLog "logs/name_of_folder_log"
    CustomLog "logs/name_of_folder_access_log" common
</VirtualHost>

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

被翻牌 2024-12-02 16:03:25

您滥用了 ServerNameServerAlias 指令。它们与文件或路径无关。它们是标识网站的域名名称(如果不是 80,还带有可选端口)。如果要移动文档根目录,则必须编辑 DocumentRoot 指令。

You are misusing the ServerName and ServerAlias directives. They have nothing to do with files or paths. They are the domain name that identifies the web site (together with an optional port if not 80). If you want to move your document root, you have to edit the DocumentRoot directive.

花伊自在美 2024-12-02 16:03:25

你可能不会那样做。指令 ServerName 不应获取 URL,而是获取域名。将根目录设置为父文件夹,使用 拒绝对其的所有访问,并允许访问您的子目录以使其正常工作。

You may not do this in that way. The directive ServerName is not supposed to get an URL but a domain name. Set the root to the parent folder, deny all access to it using <Directory> and allow access to you subdirectory to get it work.

寂寞美少年 2024-12-02 16:03:25

而不是这样做:

ServerName localhost/name_of_folder
ServerAlias www.localhost/name_of_folder

创建一个子域:

ServerName subdomain.localhost

In stead of doing:

ServerName localhost/name_of_folder
ServerAlias www.localhost/name_of_folder

Create a subdomain:

ServerName subdomain.localhost
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文