简体   繁体   English

找不到 Apache 虚拟主机 404

[英]Apache virtual host 404 not found

I just started learning php and I am trying to host locally my own php website by using XAMPP.我刚开始学习 php,我正在尝试使用 XAMPP 在本地托管我自己的 php 网站。

I wanted to create virtual host with:我想创建虚拟主机:

URL: myphpwebsite.local网址:myphpwebsite.local

Port: 8088端口:8088

But when I attempted to access this website through the browser I got a:但是当我试图通过浏览器访问这个网站时,我得到了一个:

Not Found HTTP Error 404. The requested resource is not found.未找到 HTTP 错误 404。未找到请求的资源。

Does anyone know what the problem is?有谁知道问题是什么?

My httpd-vhosts.conf我的 httpd-vhosts.conf

NameVirtualHost 127.0.0.1:8088
<VirtualHost 127.0.0.1:8088>
  DocumentRoot "C:/xampp/htdocs"
  ServerName localhost
</VirtualHost>

<VirtualHost myphpwebsite.local>
    DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
    ServerName myphpwebsite.local
    ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log"
    CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined

   <Directory "C:/Microsoft/Workspace/myphpwebsite">
    Order allow,deny
    Allow from all
   </Directory>
</VirtualHost>

And my C:\\Windows\\System32\\drivers\\etc\\hosts file:而我的 C:\\Windows\\System32\\drivers\\etc\\hosts 文件:

127.0.0.1       localhost
127.0.0.1 myphpwebsite.local

Any help would be appreciated!任何帮助,将不胜感激!

  1. make sure there's file/htaccess/index or whatever in directory you want to open, 404 may comes from that ;)确保有 file/htaccess/index 或您要打开的目录中的任何内容,404 可能来自该目录;)

  2. try using one below, eventually replace your port:尝试使用下面的一个,最终替换你的端口:

     <VirtualHost *:80> DocumentRoot "C:/Microsoft/Workspace/myphpwebsite" ServerName myphpwebsite.local </VirtualHost>
  3. the question is your Apache running/serving on port 8088?问题是您的 Apache 在端口 8088 上运行/服务吗? For example my xamp is running on 80 and 443...例如,我的 xamp 在 80 和 443 上运行...

  4. xamp control panel is very handy, it has nice logs button that will open your log files to show you php and apache errors etc. check it out. xamp 控制面板非常方便,它有很好的日志按钮,可以打开您的日志文件以显示 php 和 apache 错误等。检查一下。

Try going with default port, if it works it means that you need to play with ports if you really want to.尝试使用默认端口,如果它有效,则意味着如果您真的想要,则需要使用端口。

just a quick tip, .com is shorter than .local and if you're using chrome and it works like mine then most of the time something.local will redirect you to google search (and I like my search there, you can switch it off ;))只是一个快速提示,.com 比 .local 短,如果你使用 chrome 并且它像我的一样工作,那么大部分时间 something.local 会将你重定向到谷歌搜索(我喜欢我在那里的搜索,你可以切换它离开 ;))

I don't know if I am much help, but using WAMP, here are my settings.我不知道我是否有很大帮助,但是使用 WAMP,这是我的设置。 I am listening on port 80, I use 8080 for my tomcat server.我正在侦听端口 80,我使用 8080 作为我的 tomcat 服务器。

hosts file主机文件

127.0.0.1  local.mysite.com

httpd-vhosts.conf httpd-vhosts.conf

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

....

<Directory "c:/wamp/www">
    Options Indexes MultiViews FollowSymLinks
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "c:/wamp/www"
</VirtualHost>

<Directory "c:/wamp/www/path/to/site/root">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<VirtualHost *:80>
    ServerName local.mysite.com
    DocumentRoot "c:/wamp/www/path/to/site/root"

    ServerAdmin me@email.com

    ProxyPreserveHost Off
    RewriteEngine On
    AllowEncodedSlashes NoDecode
    #AllowEncodedSlashes On

    ErrorLog "c:/wamp/www/path/to/logs/error.log"
    CustomLog "c:/wamp/www/path/to/logs/access.log" common
</VirtualHost>

....

Then I can access my local site like this: http://local.mysite.com然后我可以像这样访问我的本地站点: http://local.mysite.com : http://local.mysite.com

Hope this helps...希望这可以帮助...

The NameVirtualHost directive needs to match the value of VirtualHost exactly, and you need to specify the port in each instance. NameVirtualHost指令需要与VirtualHost的值完全匹配,并且您需要在每个实例中指定端口。 If you want to use port 8088 for myphpwebsite.local, you'd need to do:如果您想为 myphpwebsite.local 使用端口 8088,您需要执行以下操作:

NameVirtualHost 127.0.0.1:8088
<VirtualHost 127.0.0.1:8088>
  DocumentRoot "C:/xampp/htdocs"
  ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1:8088>
    DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
    ServerName myphpwebsite.local
    ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log"
    CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined

   <Directory "C:/Microsoft/Workspace/myphpwebsite">
    Order allow,deny
    Allow from all
   </Directory>
</VirtualHost>

Notice the VirtualHost opening tags are identical;注意VirtualHost开始标签是相同的; it's the ServerName value that actually tells Apache which domain this particular directive applies to. ServerName值实际上告诉 Apache 此特定指令适用于哪个域。 Restart your server after making the changes.进行更改后重新启动服务器。 Check out this page for more information: http://httpd.apache.org/docs/2.2/vhosts/name-based.html查看此页面了解更多信息: http : //httpd.apache.org/docs/2.2/vhosts/name-based.html

Hope this helps!希望这可以帮助!

确保您使用的端口未被其他服务使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM