Ubuntu 为什么我的apache2设置总是导致301永久移动

Ubuntu 为什么我的apache2设置总是导致301永久移动,ubuntu,apache2,http-status-code-301,http-redirect,Ubuntu,Apache2,Http Status Code 301,Http Redirect,我最近在一个VPS上安装了一个apache2(2.4)服务器,试图让它与Phusion Passenger一起运行rails应用程序。这几乎是Ubuntu 14.04和apache2的全新安装。我正在尝试通过启用站点来配置VirtualHost条目。一旦我运行了一个Ensites,对的任何访问都将自动重定向到。我没有任何.htaccess文件。以下说明了我遇到的问题 这里是/etc/apache2/,目前还没有启用虚拟主机站点 [appuser@prod apache2]$ ls -l tot

我最近在一个VPS上安装了一个apache2(2.4)服务器,试图让它与Phusion Passenger一起运行rails应用程序。这几乎是Ubuntu 14.04和apache2的全新安装。我正在尝试通过启用站点来配置VirtualHost条目。一旦我运行了一个Ensites,对的任何访问都将自动重定向到。我没有任何.htaccess文件。以下说明了我遇到的问题

这里是/etc/apache2/,目前还没有启用虚拟主机站点

[appuser@prod apache2]$  ls -l
total 84
-rw-r--r-- 1 root root  7115 Jan  7 08:23 apache2.conf
drwxr-xr-x 2 root root  4096 May  8 21:46 conf-available
drwxr-xr-x 2 root root  4096 May  8 21:46 conf-enabled
-rw-r--r-- 1 root root  1782 Jan  3 09:48 envvars
-rw-r--r-- 1 root root 31063 Jan  3 09:48 magic
drwxr-xr-x 2 root root 12288 May  8 22:11 mods-available
drwxr-xr-x 2 root root  4096 May 13 00:28 mods-enabled
-rw-r--r-- 1 root root   320 Jan  7 08:23 ports.conf
drwxr-xr-x 2 root root  4096 May 12 23:37 sites-available
drwxr-xr-x 2 root root  4096 May 13 00:40 sites-enabled
drwxr-xr-x 2 root root  4096 May  8 22:24 ssl
[appuser@prod apache2]$  ls -l sites-enabled/
total 0
下面是/etc/sites available/bulletin.vhost.conf:

[appuser@prod apache2]$  cat sites-available/bulletin.vhost.conf
#NameVirtualHost *:80
#ServerName bulletin.xorg

<VirtualHost *:80>
  ServerName bulletin.xorg:80
  DocumentRoot /home/appuser/www/bulletin/public
  <Directory /home/appuser/www/bulletin/public>
    AllowOverride all
    Options -MultiViews
    Require all granted
    PassengerRuby /home/appuser/.rvm/gems/ruby-1.9.3-p545/wrappers/ruby
  </Directory>

</VirtualHost>
现在,我正在启用此虚拟主机:

[appuser@prod apache2]$  sudo a2ensite bulletin.vhost
[sudo] password for appuser: 
Enabling site bulletin.vhost.
To activate the new configuration, you need to run:
  service apache2 reload
[appuser@prod apache2]$ )`reload': sudo service apache2 reload
 * Reloading web server apache2
[appuser@prod apache2]$  sudo service apache2 restart
 * Restarting web server apache2
AH00558: apache2: Could not reliably determine the server's fully 
  qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to
  suppress this message
现在我很难访问http://xorg或。我总是得到“301永久移动”的状态

如果对此感兴趣,我已经启用了以下mods,并在前面创建了一个自签名ssl证书(但我不认为它有什么相关性):


我真的很困惑。提前谢谢。

我终于明白了。总之,应用服务器(Phusion Passenger)获取了我的应用程序需要ssl的生产设置

这是一个Rails 3.2应用程序,它有以下条目

config/environments/production.rb:  
                # Force all access to the app over SSL, use 
                # Strict-Transport-Security, and use secure cookies.
config/environments/production.rb:  
                config.force_ssl = true

因此,不是apache2重写模块强制301移动永久状态,而是我的应用程序服务器执行了该操作。另外,因为我在apache2中只有一个VirtualHost,并且我禁用了默认站点(根据apache2.4安装附带的000-default.conf配置)。任何对*.xorg的访问都会失败,并由第一个(也是唯一一个)VirtualHost提供服务,即bulletin.xorg。然后,由于bulletin.xorg应用程序在Rails中的强制ssl设置,http->总是发生。

感谢您回答自己的问题。帮我解决了我的问题。
[appuser@prod apache2]$  wget http://xorg
--2014-05-13 00:58:45--  http://xorg/
Resolving xorg (xorg)... 127.0.0.1
Connecting to xorg (xorg)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://xorg/ [following]
--2014-05-13 00:58:45--  https://xorg/
Connecting to xorg (xorg)|127.0.0.1|:443... connected.
OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Unable to establish SSL connection.

[appuser@prod apache2]$  wget http://bulletin.xorg
--2014-05-13 01:01:18--  http://bulletin.xorg/
Resolving bulletin.xorg (bulletin.xorg)... 127.0.0.1
Connecting to bulletin.xorg (bulletin.xorg)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://bulletin.xorg/ [following]
--2014-05-13 01:01:19--  https://bulletin.xorg/
Connecting to bulletin.xorg (bulletin.xorg)|127.0.0.1|:443... connected.
OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Unable to establish SSL connection.
[appuser@prod apache2]$  ls -l ssl/
total 8
-rw-r--r-- 1 root root 1350 May  8 22:24 redmine.crt
-rw-r--r-- 1 root root 1704 May  8 22:24 redmine.key

[appuser@prod apache2]$  ls -l mods-enabled/
.
.
lrwxrwxrwx 1 root root 30 May 13 00:28 rewrite.load -> ../mods-available/rewrite.load
.
.
lrwxrwxrwx 1 root root 26 May  8 21:47 ssl.conf -> ../mods-available/ssl.conf
lrwxrwxrwx 1 root root 26 May  8 21:47 ssl.load -> ../mods-available/ssl.load
.
.
config/environments/production.rb:  
                # Force all access to the app over SSL, use 
                # Strict-Transport-Security, and use secure cookies.
config/environments/production.rb:  
                config.force_ssl = true