【问题标题】:localhost/phpmyadmin can't access when setting virtualhost设置虚拟主机时localhost / phpmyadmin无法访问
【发布时间】:2014-09-26 13:40:26
【问题描述】:

情况如下:

我有一个项目,我想在 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\drivers\etc\host

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 ?请指导我。

请帮帮我。

【问题讨论】:

标签: php phpmyadmin xampp virtualhost


【解决方案1】:

修改你的主机文件如下:

127.0.0.1 localhost
127.0.0.1 coye.com 

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

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

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

【讨论】:

    【解决方案2】:

    我终于找到了解决我的问题的方法,希望这对你遇到类似问题的其他人有所帮助:

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

    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
    

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

    【讨论】:

      【解决方案3】:

      看到你必须将原始配置保留在主机文件中

      127.0.0.1 本地主机

      要访问 phpmyadmin,您需要转到 phpmyadmin.local 而不是 localhost/phpmyadmin

      虚拟主机配置

      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>
      

      让我知道它是否有效。

      【讨论】:

      • 您能否编辑您的答案并告诉我必须在主机和 httpd-vhost.conf 文件中进行哪些更改
      • 我想在本地使用 www.coye.com 运行我的项目 coye,这就是我设置虚拟主机的原因。从您的代码中,我将无法运行 www.coye.com
      猜你喜欢
      • 2012-12-14
      • 2014-02-03
      • 2014-03-15
      • 2011-10-20
      • 2020-07-17
      • 1970-01-01
      • 2014-12-04
      • 1970-01-01
      • 2013-09-16
      相关资源
      最近更新 更多