Ubuntu 14.04:Apache 2.4.7 virtualhost不工作/重定向

Ubuntu 14.04:Apache 2.4.7 virtualhost不工作/重定向,apache,ubuntu,virtualhost,Apache,Ubuntu,Virtualhost,我的Ubuntu14.04机器上安装了Apache2.4.7,我的一些虚拟主机不同意我的看法。我有5个虚拟主机,我正在尝试运行;其中3人工作,2人不工作。两个不起作用的.conf文件是: 002 tmpnet.conf <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/tmpnet ServerName tmpnet <Directory

我的Ubuntu14.04机器上安装了Apache2.4.7,我的一些虚拟主机不同意我的看法。我有5个虚拟主机,我正在尝试运行;其中3人工作,2人不工作。两个不起作用的.conf文件是:

002 tmpnet.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/tmpnet
    ServerName  tmpnet
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/html/tmpnet/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        #Order allow,deny
        #allow from all
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/tmpcom
    ServerName  tmpcom
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/html/tmpcom>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        #Order allow,deny
        #allow from all
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
当你试图拜访他们的时候。如果我通过localhost(即localhost/html/tmpnet)访问它们,它工作得非常好,只是在尝试使用虚拟主机时不行

sudo a2dissite 000-default.conf
我的主机文件是:

127.0.0.1   localhost
127.0.1.1   Eagle
127.0.1.1   tmpcom
127.0.1.1   tmpbiz
127.0.1.1   tmporg
127.0.1.1   tmpnet
127.0.1.1   thatsmybrick

# 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
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups on
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride All
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf
我的apache2.conf是:

127.0.0.1   localhost
127.0.1.1   Eagle
127.0.1.1   tmpcom
127.0.1.1   tmpbiz
127.0.1.1   tmporg
127.0.1.1   tmpnet
127.0.1.1   thatsmybrick

# 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
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups on
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride All
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf
Mutex文件:${APACHE\u LOCK\u DIR}默认值
PidFile${APACHE_PID_文件}
超时300
继续
MaxKeepAliveRequests 100
保持超时
#这些需要在/etc/apache2/envvars中设置
用户${APACHE\u RUN\u User}
组${APACHE\u RUN\u Group}
主机名查找
ErrorLog${APACHE_LOG_DIR}/error.LOG
日志级别警告
包括可选mods启用/*.加载
IncludeOptional mods enabled/*.conf
Include ports.conf
选项如下符号链接
允许超越所有
要求全部拒绝
允许超越所有
要求所有授权
选项索引跟随符号链接
允许超越所有
要求所有授权
AccessFileName.htaccess
要求全部拒绝
日志格式“%v:%p%h%l%u%t\%r\“%>s%O\”%{Referer}i\“\”%{User-Agent}i\\”vhost\u
日志格式“%h%l%u%t\%r\”%>s%O\“%%{Referer}i\\\“%%{User Agent}i\\”组合
日志格式“%h%l%u%t\%r\“%>s%O”通用
日志格式“%{Referer}i->%U”Referer
日志格式“%{User agent}i”代理
IncludeOptional conf enabled/*.conf
IncludeOptional sites enabled/*.conf
我已经在这上面呆了很长一段时间了,我真的很感谢你的帮助。任何指向正确方向的东西都会令人惊奇


谢谢你

你还面临这个问题吗

您是否查看了位于/var/log/apache2/error.log的错误日志。错误日志是不言自明的,可以很好地说明问题

我的机器上的错误显示了这一点(错误声明的后半部分)

.htaccess:命令“重写引擎”无效,可能拼写错误或 由服务器配置中未包含的模块定义

在我的例子中,没有启用Apache模块重写。我启用了模块,瞧,虚拟主机设置激活了

我还看到您正在使用语句“AllowOverride All”,这表示您正在尝试使用重写模块。如果尚未启用模块“重写”,请使用命令
sudo a2enmod rewrite
,然后重新启动apache2
sudo/etc/init.d/apache2 restart


看看这是否有用

这可能有点晚了,不确定是否找到了解决方案,但我就是这么做的。在花了好几个小时修改配置文件和调整vhost之后,我决定放弃2000。。。默认站点和重新加载的apache。一旦我这样做了,重定向就会像eExected一样工作。我不知道当服务器上有多个站点时,如果默认为第一个加载的vhost或。。。我总是觉得apache必须有一个默认主机,这一点我可能是错的。

我面临这个问题,结果我不得不禁用默认虚拟主机

sudo a2dissite 000-default.conf

重点是:

包括启用的可选站点/*.conf

这意味着它将只包括文件名末尾带有
.conf
的虚拟主机文件

重命名它们,或更改指令

再见,
Gelma

如果您是从precise(12.04)升级,则需要向虚拟主机配置文件添加.conf扩展名

例如,以前您有此配置

/etc/apache2/sites-available/project
然后您需要向它添加.conf扩展名

/etc/apache2/sites-available/project.conf
当然,您必须在站点启用文件夹中创建一个新的符号链接,cd到站点启用文件夹,然后

sudo ln -s ../sites-available/project.conf 

重新启动apache,您就完成了。

我不仅必须禁用默认设置:

sudo a2dissite 000-default.conf
但我也不得不以sudo的形式重新加载apache——没有sudo,就不能正确地重新加载

sudo service apache2 reload

我正在测试相同的设置:

  • 带mod_重写的Apache 2.4.7(sudo a2enable rewrite)

  • Ubuntu 14.04 LTS

在使用基本指示灯的干净安装()上,我在可用的站点上使用以下内容(启用站点的软链接)


ServerName test.cubeinspire.com
DocumentRoot/home/test/public\u html
CustomLog/home/test/log/access\u log组合
ErrorLog/home/test/log/error\u log
命令允许,拒绝
通融
要求所有授权
只有在使用该代码的情况下,所有这些都非常有效。(请注意,要求所有已授予的,这是Apache 2.4.7的新要求)

当我添加以下代码时:

<VirtualHost *:80>
  ServerName redirectme.cubeinspire.com
  Options +FollowSymLinks
  RewriteEngine on
  Redirect 301 / http://test.cubeinspire.com/
<Directory "/home/test/public_html">
  AllowOverride None
  Require all granted
</Directory>
</VirtualHost>

ServerName重定向me.cubeinspire.com
选项+FollowSymLinks
重新启动发动机
重定向301/http://test.cubeinspire.com/
不允许超限
要求所有授权
然后,当我访问redirectme.cubeinspire.com时,我陷入了301重定向循环。 这是一段在以前的Apache版本上运行的非常简单的代码,文档中没有太多说明


因此,我想该版本仍然存在一些缺陷,我不鼓励在生产服务器上使用它。

谢谢!!!我运行了
A2000 default.conf
并将
.conf
添加到我现有的文件中,它成功了!我想你没有读过这个问题。他的文件名为
.conf
,仍然没有加载。