Laravel路由无法在Apache中使用虚拟主机中的自定义端口

时间:2014-03-17 11:11:07

标签: apache mod-rewrite laravel virtualhost selinux

我有一台运行Linux的服务器。它是一个具有ip 10.61.0.3的VM。目前用于在/var/www/html端口80处为我的网站提供服务。

我想从位于/var/www/laraapp的此服务器向端口8080提供Laravel应用。

我目前为虚拟主机配置的apache是​​:

<VirtualHost *:8080>
  ServerName 10.61.0.3:8080
  DocumentRoot /var/www/laraapp/public
</VirtualHost>

当我访问10.61.0.3:8080时,没有显示任何内容。以下是关于apache error_logs的内容:

[Mon Mar 17 17:28:43 2014] [notice] caught SIGTERM, shutting down
[Mon Mar 17 17:28:48 2014] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
[Mon Mar 17 17:28:48 2014] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Mar 17 17:28:48 2014] [notice] Digest: generating secret for digest authentication ...
[Mon Mar 17 17:28:48 2014] [notice] Digest: done
[Mon Mar 17 17:28:48 2014] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.4.7 configured -- resuming normal operations
[Mon Mar 17 17:28:48 2014] [error] avahi_entry_group_add_service_strlst("10.61.0.3") failed: Invalid host name

我该怎么办?

注意:

  • 我可以使用内置的PHP Web服务器运行我的larapp。
  • LoadModule rewrite_module modules/mod_rewrite.so已在/etc/httpd/conf/httpd.conf
  • 中取消注释
  • Listen 8080已在/etc/httpd/conf/httpd.conf
  • 中声明

1 个答案:

答案 0 :(得分:0)

在Apache文档中,ServerName应该类似于域名http://httpd.apache.org/docs/2.2/mod/core.html#servername

尝试将ServerName 10.61.0.3更改为ServerName example.com

不要忘记将127.0.0.1 example.com添加到/etc/hosts

如果您希望在端口8080上运行VirtualHost,则必须定义NameVirtualHost http://httpd.apache.org/docs/2.2/vhosts/examples.html#port

例如:

Listen 8080

NameVirtualHost 10.61.0.3:8080

<VirtualHost 10.61.0.3:8080>
    ServerName example.com  
    DocumentRoot /var/www/laraapp/public  
</VirtualHost>