设置虚拟主机时,localhost / phpmyadmin无法访问

时间:2014-08-04 06:06:55

标签: php phpmyadmin xampp virtualhost

情况如下:

我有一个项目,我希望在localhost上运行http://www.coye.com/,我已经设置了一个虚拟主机,运行方式如下:

F:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf:

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs"
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs/coye"
ServerName coye.com
ServerAlias www.coye.com
RewriteEngine on

#Added New by Sandeep - Start
RewriteCond %{HTTP_HOST} !^www.coye\.com$ [NC]
RewriteRule ^(.*)$ http://www.coye.com$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/images
RewriteCond %{REQUEST_URI} !^/css
RewriteCond %{REQUEST_URI} !^/js
RewriteCond %{REQUEST_URI} !^/fckeditor
RewriteCond %{REQUEST_URI} !^/securityimage
RewriteCond %{REQUEST_URI} !^/sitemap.txt
RewriteRule ^/(.*)$ /index.php?request=$1 [PT,QSA,L]
</VirtualHost>

C:\ Windows \ System32下\驱动程序\等\宿主

127.0.0.1 localhost
127.0.0.1 coye.com 
127.0.0.1 www.coye.com 
127.0.0.1 api.coye.com 
127.0.0.1 merchant.coye.com 
127.0.0.1 admin.coye.com

现在我想运行PHPMyadmim,但无法通过localhost/phpmyadmin访问。 我需要做些什么来改进访问PHPMyadmin?请指导我。

请帮我解决这个问题。

3 个答案:

答案 0 :(得分:5)

最后我找到了解决问题的方法,希望这对其他人有帮助,你将面临类似的问题:

我必须添加这段额外的代码:

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs"
ServerName localhost
</VirtualHost>

所以最终文件将是 -

httpd-vhosts.conf:

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs"
ServerName localhost
</VirtualHost>


<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs/coye"
ServerName coye.com
ServerAlias www.coye.com
RewriteEngine on

#Added New by Sandeep - Start
RewriteCond %{HTTP_HOST} !^www.coye\.com$ [NC]
RewriteRule ^(.*)$ http://www.coye.com$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/images
RewriteCond %{REQUEST_URI} !^/css
RewriteCond %{REQUEST_URI} !^/js
RewriteCond %{REQUEST_URI} !^/fckeditor
RewriteCond %{REQUEST_URI} !^/securityimage
RewriteCond %{REQUEST_URI} !^/sitemap.txt
RewriteRule ^/(.*)$ /index.php?request=$1 [PT,QSA,L]
</VirtualHost>

主机文件:

127.0.0.1 localhost
127.0.0.1 coye.com 
127.0.0.1 www.coye.com 
127.0.0.1 api.coye.com 
127.0.0.1 merchant.coye.com 
127.0.0.1 admin.coye.com

感谢所有试图帮助我的人。

答案 1 :(得分:0)

请参阅您必须将原始配置保留在主机文件

127.0.0.1 localhost

要访问phpmyadmin,您需要转到 phpmyadmin.local 而不是 的本地主机/ phpmyadmin的

Virtualhost配置

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/local/zend/apache2/htdocs/l2/public"
    ServerName coye.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot ""
    ServerName **phpmyadmin.dev**
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

让我知道它是否有效。

答案 2 :(得分:0)

修改您的主机文件,如下所示:

127.0.0.1 localhost
127.0.0.1 coye.com 

然后将您的“子域名”(包括www)映射到您的apache文件中,您应该没问题

<VirtualHost 127.0.0.1:80>
  DocumentRoot "F:/xampp/htdocs"
  ServerName coye.com
  ServerAlias subdomain.coye.com
</VirtualHost>

Windows中的hosts文件可用作域重定向器,而不是全名重定向器,所有子域(包括www.domain.com)都必须在apache虚拟主机中使用别名。