【问题标题】:Virtual Host is not working in Zend Framework after multiple tries at fixing things多次尝试修复问题后,虚拟主机无法在 Zend Framework 中运行
【发布时间】:2015-02-15 06:47:25
【问题描述】:

在 sites-available 和 sites-enabled 文件夹中,我有一个名为“zend-framework.conf”的 conf 文件。这是我在文件中包含的内容。

 <VirtualHost *:80>
     # The ServerName directive sets the request scheme, hostname and port that
     # the server uses to identify itself. This is used when creating
     # redirection URLs. In the context of virtual hosts, the ServerName
     # specifies what hostname must appear in the request's Host: header to
     # match this virtual host. For the default virtual host (this file) this
     # value is not decisive as it is used as a last resort host regardless.
     # However, you must set it for any further virtual host explicitly.
     ServerName zendlocalhost
     ServerAlias zendlocalhost
     ServerAdmin root@localhost
     DocumentRoot /var/www/zend-framework/public
     SetEnv APPLICATION_ENV "development"
     <Directory /var/www/zend-framework/public>
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from All
     </Directory>

     # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
     # error, crit, alert, emerg.
     # It is also possible to configure the loglevel for particular
     # modules, e.g.
     #LogLevel info ssl:warn

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

     # For most configuration files from conf-available/, which are
     # enabled or disabled at a global level, it is possible to
     # include a line for only one particular virtual host. For example the
     # following line enables the CGI configuration for this host only
     # after it has been globally disabled with "a2disconf".
     #Include conf-available/serve-cgi-bin.conf 
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

这是我的 etc/hosts 文件中的内容

127.0.0.1   localhost
#127.0.1.1  lazerorca-iMac
127.0.0.1   zendlocalhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

这就是我的 ports.conf 文件中的内容。我收到一条消息,说 NameVirtualHost *:80 将在以后的版本中被弃用。我尝试添加它只是因为我在另一个问题中看到了它

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80

<IfModule ssl_module>
 Listen 443
</IfModule>

<IfModule mod_gnutls.c>
 Listen 443
</IfModule>

NameVirtualHost *:80

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

这是我去http://zendlocalhost时遇到的错误

内部服务器错误

服务器遇到内部错误或配置错误,并且 无法完成您的请求。

请通过root@localhost联系服务器管理员告知 他们发生此错误的时间以及您执行的操作 就在这个错误之前。

有关此错误的更多信息可能在服务器错误中可用 记录。

这就是 access.log 所说的

127.0.0.1 - - [16/Dec/2014:15:05:22 -0500] "GET / HTTP/1.1" 500 798 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:35.0 ) 壁虎/20100101 火狐/35.0"

这就是error.log所说的

[2014 年 12 月 16 日星期二 15:25:20.271792] [core:alert] [pid 4825] [client 127.0.0.1:60826] /var/www/zend-framework/public/.htaccess:无效命令“RewriteEngine”,可能拼写错误或由模块定义 包含在服务器配置中

我检查了 .htaccess 文件,对我来说它看起来不错,但显然不是。这是 .htaccess 文件中的内容

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

有趣的是,如果我去http://zendlocalhost/phpmyadmin 它会拉起来 如果我转到 127.0.0.1,它会提取通用 Ubuntu apache index.html 文件 我对 Zend 很陌生,因为这是我第一次尝试它。我知道有一些疯狂的 URL 重写等。我原以为转到根地址会拉出 index.php 文件。

提前感谢您的帮助

【问题讨论】:

    标签: zend-framework virtual host


    【解决方案1】:

    Apache 不理解RewriteEngine,这是您.htaccess 中的第一个指令。这意味着 mod_rewrite 未启用。如果您使用的是 Ubuntu,请运行 sudo a2enmod rewrite,然后重新启动 Apache 并重试。

    【讨论】:

      猜你喜欢
      • 2014-08-06
      • 1970-01-01
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 2011-04-24
      • 1970-01-01
      • 2012-08-14
      相关资源
      最近更新 更多