HTTPS自动重新路由到生产服务器而不是开发服务器

时间:2013-10-23 00:24:48

标签: apache .htaccess ssl https

网络主机:Bluehost
SSL:通配符SSL
Rails:v4
Ruby:v2
开发域名:dev.mydomain.com
Pro Domain:www.mydomain.com

我正在尝试测试https://个连接。我只在开发应用程序中修改了我的rails应用程序和我的apache .htaccess文件。我遇到了几个问题,我认为这两个问题都是由于第一个问题而出现的:

1)最大的问题:使用http://dev.mydomain.com/whatever时,一切都按预期工作。但是在使用https://dev.mydomain.com/whatever时,它会以生产模式运行!即使域是dev.mydomain.com,rails应用程序也在生产模式下运行。正在提供预编译资产......但问题是,这些文件实际上并不存在于开发应用程序目录中。它们仅存在于生产应用程序目录中(完全独立)。这意味着即使URL指向dev.mydomain.com/whatever,所有内容都通过mydomain.com/whatever ...实际运行,并且我的rails应用程序的生产应用程序正在运行。为什么会这样?!

2)在我的.htaccess文件中,我试图使用以下方法强制进行SSL连接:

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "dev.mydomain.com"
ErrorDocument 403 https://dev.mydomain.com

然而,即使我已正确设置Apache授权参数,它也不再提示我输入登录/通过组合。我相信这是因为使用SSL时,所使用的实际目录根本不是开发文件夹(参见第1个问题)。

这是Apache配置错误吗?我没有对httpd.conf做任何事情,我的网站主机自动设置了SSL证书。

编辑:“完整”.htaccess代码......

#SSLOptions +StrictRequire
#SSLRequireSSL
#SSLRequire %{HTTP_HOST} eq "dev.mydomain.com"
#ErrorDocument 403 https://dev.mydomain.com

#AuthUserFile "/home/account/.htpasswds/htuser"
#AuthGroupFile "/home/account/.htpasswds/htgroup"
#AuthName "Login Required"
#AuthType Basic
#require group owners administrators


# General Apache options
Options -Indexes
Options -MultiViews
Options +SymLinksIfOwnerMatch +ExecCGI
SetEnv TZ Canada/Eastern
Header unset ETag
FileETag None
AddDefaultCharset UTF-8
DefaultLanguage en


# Compress output
AddOutputFilterByType DEFLATE text/html text/plain text/css text/js text/javascript application/javascript application/xml text/xml image/gif image/jpeg image/jpg image/png image/vnd.microsoft.icon image/x-icon application/vnd.ms-fontobject font/ttf font/otf image/svg+xml




# User added MIME types
AddType video/x-flv .flv
AddType video/mp4 .m4v .mp4 .f4v
AddType video/ogg .ogv
AddType audio/ogg .oga
AddType image/jpeg .jpeg .jpg .jpe
AddType image/svg+xml .svg .svgz
AddType application/vnd.ms-fontobject .eot
AddType font/otf .otf
AddType font/ttf .ttf


# Set Expires info
ExpiresActive On
ExpiresByType image/gif "access plus 365 days"
ExpiresByType image/jpeg "access plus 365 days"
ExpiresByType image/png "access plus 365 days"
ExpiresByType image/x-icon "access plus 365 days"
ExpiresByType application/x-shockwave-flash "access plus 365 days"
ExpiresByType application/x-javascript "access plus 365 days"
ExpiresByType application/javascript "access plus 365 days"
ExpiresByType text/css "access plus 365 days"
ExpiresByType text/html "access plus 1 day"




RewriteEngine On
RewriteBase /


# Temporarily down for maintenance!
#RewriteCond %{HTTP:X-FORWARDED-FOR} !^xxx\.xxx\.xxx\.xxx
#RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt)$
#RewriteRule .* - [R=503,L]


# Reroute all requests on dev site to https
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^dev.mydomain.com$
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}



PassengerEnabled on
PassengerResolveSymlinksInDocumentRoot on
RailsEnv development
RailsBaseURI /
PassengerAppRoot /home/account/rails_apps/dev.MyDomain


ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
# Start CloudFlare:mydomain.com rewrite. Do not Edit 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^mydomain.com 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
# End CloudFlare rewrite. 

1 个答案:

答案 0 :(得分:0)

数字......我花了几天的时间来寻找这个问题,并且在与Bluehost的技术支持人员联系之前几秒钟就找到了解决方案。

http://www.crsr.net/Notes/Apache-HTTPS-virtual-host.html

我需要在httpd.conf中为我的Apache配置添加一个VirtualHost条目。 Bluehost在安装SSL证书时已经自动生成了一个,但是dev.mydomain.com没有一个

<VirtualHost xxx.xxx.xxx.xxx:443>
    ServerName dev.mydomain.com
    ServerAlias www.dev.mydomain.com
    DocumentRoot /home/account/public_html/subdomains/dev
    ServerAdmin webmaster@mydomain.com
    UseCanonicalName Off
    CustomLog /usr/local/apache/domlogs/dev.mydomain.com combined
    CustomLog /usr/local/apache/domlogs/dev.mydomain.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
    ## User account # Needed for Cpanel::ApacheConf
    UserDir enabled account
    <IfModule mod_suphp.c>
        suPHP_UserGroup account account
    </IfModule>
    <IfModule !mod_disable_suexec.c>
        <IfModule !mod_ruid2.c>
            SuexecUserGroup account account
        </IfModule>
    </IfModule>
    <IfModule mod_ruid2.c>
        RUidGid account account
    </IfModule>
    ScriptAlias /cgi-bin/ /home/account/public_html/subdomains/dev/cgi-bin/
    SSLEngine on

    SSLCertificateFile /var/cpanel/ssl/installed/certs/_wildcard__mydomain_com_[blah-blah-blah].crt
    SSLCertificateKeyFile /var/cpanel/ssl/installed/keys/[blah-blah-blah].key
    SSLCACertificateFile /var/cpanel/ssl/installed/cabundles/COMODO_CA_Limited_[blah-blah-blah].cabundle
    CustomLog /usr/local/apache/domlogs/dev.mydomain.com-ssl_log combined
    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
    <Directory "/home/account/public_html/subdomains/dev/cgi-bin">
        SSLOptions +StdEnvVars
    </Directory>

    # To customize this VirtualHost use an include file at the following location
    # Include "/usr/local/apache/conf/userdata/ssl/2/account/mydomain.com/*.conf"

</VirtualHost>