V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
pppguest3962
V2EX  ›  Apache

配置好的 CentOS httpd SSL 服务,为什么不能网页不能自动重定向 https?

  •  
  •   pppguest3962 · 2018-04-28 17:45:27 +08:00 · 3808 次点击
    这是一个创建于 2412 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这个主机完整是 https://192.168.89.41:8080

    我想别人在访问 http://192.168.89.41:8080,自动跳往 https://192.168.89.41:8080 但按目前调试的配置,访问 http://192.168.89.41:8080,浏览器会显示出一个 html 的代码明文:

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    
    <html><head>
    <title>400 Bad Request</title>
    </head><body>
    <h1>Bad Request</h1>
    <p>Your browser sent a request that this server could not understand.<br />
    Reason: You're speaking plain HTTP to an SSL-enabled server port.<br />
    Instead use the HTTPS scheme to access this URL, please.<br />
    <blockquote>Hint: <a href="https://localhost:8080/"><b>https://localhost:8080/</b></a></blockquote></p>
    </body></html>
    

    下面是节选 httpd.conf,配置有多个 VirtualHost,但是只想 8080 这个主机启用 https, mod_ssl 确定是装好的,证书已经使用上的了,

    cat /etc/httpd/conf/httpd.conf

    #8080,Test
    <VirtualHost *:8080> 
       SSLEngine on
       SSLCertificateFile "/etc/httpd/conf/ssl_key/server.crt"
       SSLCertificateKeyFile "/etc/httpd/conf/ssl_key/server.key"
       SSLOptions StdEnvVars
       SSLProtocol all -SSLv2 -SSLv3
       SSLHonorCipherOrder on
       SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW:!RC4:
    
       DocumentRoot /opt/test1
       DocumentRoot "/opt/test1"
         <Directory "/opt/test1">
            Options Indexes FollowSymLinks
            #Options FollowSymLinks
            #Options Indexes 
            AllowOverride None
            Order allow,deny
            Allow from all
         </Directory>
    </VirtualHost>
    
    #9090,Test2
    <VirtualHost *:9090>
       DocumentRoot /opt/test2
       DocumentRoot "/opt/test2"
         <Directory "/opt/test2">
            Options Indexes FollowSymLinks
            #Options FollowSymLinks
            #Options Indexes
            AllowOverride None
            Order allow,deny
            Allow from all
         </Directory>
    </VirtualHost>
    

    cat /opt/test1/.htaccess

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
    
    6 条回复    2018-04-30 15:41:06 +08:00
    mokeyjay
        1
    mokeyjay  
       2018-04-28 18:27:10 +08:00
    这类教程网上太多,建议搜点来看看,就搜“ apache https 重定向”
    或者直接上面板可能更适合你,例如 https://www.bt.cn/
    Tink
        2
    Tink  
       2018-04-28 18:43:42 +08:00 via iPhone
    端口重复
    twl007
        3
    twl007  
       2018-04-28 19:00:47 +08:00 via iPhone
    AllowOverride All

    设成这个
    v2register
        4
    v2register  
       2018-04-29 00:40:12 +08:00
    a2enmod rewrite
    pppguest3962
        5
    pppguest3962  
    OP
       2018-04-30 15:09:23 +08:00
    @mokeyjay,谢谢您相告有面板控制这个操作。。。。

    @Tink,不像是端口有重复。。。

    @twl007,没有效果,调完后,重启服务跟原来效果一样。

    @v2register,没效果。。。


    经过两天折腾,还是搞不出什么变化。。。
    我把我完整的配置贴出来,麻烦请高手们再帮我看看吧。。。。


    ```
    [root@TeLinux /root]$ cat /etc/httpd/conf/httpd.conf
    #80,Default_PHP,froum
    #7070,netDisk
    #8080,test1
    #9090,test2

    ServerName localhost:80
    ServerName localhost:7070
    ServerName localhost:8080
    ServerName localhost:9090

    ServerTokens OS
    ServerRoot "/etc/httpd"
    PidFile run/httpd.pid
    Timeout 60
    KeepAlive Off
    MaxKeepAliveRequests 100
    KeepAliveTimeout 15

    Listen 80
    Listen 7070
    Listen 8080
    Listen 9090

    #Include conf.d/*.conf

    #User apache
    #Group apache

    User vftpuser
    Group vftpuser

    #BBS
    <VirtualHost *:80>
    DocumentRoot /opt/bbs
    DocumentRoot "/opt/bbs"
    <Directory "/opt/bbs">
    Options Indexes FollowSymLinks
    DirectoryIndex index.php index.htm index.html
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>

    #7070,NetDisk
    <VirtualHost *:7070>
    DocumentRoot /opt/netdisk
    DocumentRoot "/opt/netdisk"
    <Directory "/opt/netdisk">
    Options Indexes FollowSymLinks
    #DirectoryIndex index.php index.htm index.html
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>

    #8080,Test
    <VirtualHost *:8080>
    SSLEngine on
    SSLOptions StdEnvVars
    SSLProtocol all -SSLv2 -SSLv3
    SSLHonorCipherOrder on
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW:!RC4:
    SSLCertificateFile "/etc/httpd/conf/ssl_key/server.crt"
    SSLCertificateKeyFile "/etc/httpd/conf/ssl_key/server.key"

    DocumentRoot /opt/test1
    DocumentRoot "/opt/test1"
    <Directory "/opt/test1">
    Options Indexes FollowSymLinks
    #Options FollowSymLinks
    #Options Indexes
    #AllowOverride None
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>

    #9090,Test2
    <VirtualHost *:9090>
    DocumentRoot /opt/test2
    DocumentRoot "/opt/test2"
    <Directory "/opt/test2">
    Options Indexes FollowSymLinks
    #Options FollowSymLinks
    #Options Indexes
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>

    LoadModule auth_basic_module modules/mod_auth_basic.so
    LoadModule auth_digest_module modules/mod_auth_digest.so
    LoadModule authn_file_module modules/mod_authn_file.so
    LoadModule authn_alias_module modules/mod_authn_alias.so
    LoadModule authn_anon_module modules/mod_authn_anon.so
    LoadModule authn_dbm_module modules/mod_authn_dbm.so
    LoadModule authn_default_module modules/mod_authn_default.so
    LoadModule authz_host_module modules/mod_authz_host.so
    LoadModule authz_user_module modules/mod_authz_user.so
    LoadModule authz_owner_module modules/mod_authz_owner.so
    LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
    LoadModule authz_dbm_module modules/mod_authz_dbm.so
    LoadModule authz_default_module modules/mod_authz_default.so
    LoadModule ldap_module modules/mod_ldap.so
    LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
    LoadModule include_module modules/mod_include.so
    LoadModule log_config_module modules/mod_log_config.so
    LoadModule logio_module modules/mod_logio.so
    LoadModule env_module modules/mod_env.so
    LoadModule ext_filter_module modules/mod_ext_filter.so
    LoadModule mime_magic_module modules/mod_mime_magic.so
    LoadModule expires_module modules/mod_expires.so
    LoadModule deflate_module modules/mod_deflate.so
    LoadModule headers_module modules/mod_headers.so
    LoadModule usertrack_module modules/mod_usertrack.so
    LoadModule setenvif_module modules/mod_setenvif.so
    LoadModule mime_module modules/mod_mime.so
    LoadModule dav_module modules/mod_dav.so
    LoadModule status_module modules/mod_status.so
    LoadModule autoindex_module modules/mod_autoindex.so
    LoadModule info_module modules/mod_info.so
    #LoadModule dav_fs_module modules/mod_dav_fs.so
    LoadModule vhost_alias_module modules/mod_vhost_alias.so
    LoadModule negotiation_module modules/mod_negotiation.so
    LoadModule dir_module modules/mod_dir.so
    LoadModule actions_module modules/mod_actions.so
    LoadModule speling_module modules/mod_speling.so
    LoadModule userdir_module modules/mod_userdir.so
    LoadModule alias_module modules/mod_alias.so
    LoadModule substitute_module modules/mod_substitute.so
    LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
    LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
    LoadModule proxy_connect_module modules/mod_proxy_connect.so
    LoadModule cache_module modules/mod_cache.so
    LoadModule suexec_module modules/mod_suexec.so
    LoadModule disk_cache_module modules/mod_disk_cache.so
    LoadModule cgi_module modules/mod_cgi.so
    LoadModule php5_module modules/libphp5.so

    LoadModule ssl_module modules/mod_ssl.so

    AddType application/x-httpd-php .php

    TypesConfig /etc/mime.types
    DefaultType text/plain

    <IfModule mod_mime_magic.c>
    MIMEMagicFile conf/magic
    </IfModule>


    Alias /icons/ "/var/www/icons/"
    <Directory "/var/www/icons">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>

    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

    <Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
    </Directory>

    IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
    AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

    AddIconByType (TXT,/icons/text.gif) text/*
    AddIconByType (IMG,/icons/image2.gif) image/*
    AddIconByType (SND,/icons/sound2.gif) audio/*
    AddIconByType (VID,/icons/movie.gif) video/*
    AddIcon /icons/binary.gif .bin .exe
    AddIcon /icons/binhex.gif .hqx
    AddIcon /icons/tar.gif .tar
    AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
    AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
    AddIcon /icons/a.gif .ps .ai .eps
    AddIcon /icons/layout.gif .html .shtml .htm .pdf
    AddIcon /icons/text.gif .txt
    AddIcon /icons/c.gif .c
    AddIcon /icons/p.gif .pl .py
    AddIcon /icons/f.gif .for
    AddIcon /icons/dvi.gif .dvi
    AddIcon /icons/uuencoded.gif .uu
    AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
    AddIcon /icons/tex.gif .tex
    AddIcon /icons/bomb.gif /core
    AddIcon /icons/back.gif ..
    AddIcon /icons/hand.right.gif README
    AddIcon /icons/folder.gif ^^DIRECTORY^^
    AddIcon /icons/blank.gif ^^BLANKICON^^
    DefaultIcon /icons/unknown.gif

    AddDefaultCharset UTF-8
    #AddDefaultCharset GB2312
    #AddDefaultCharset off
    #AddDefaultCharset on
    #AddDefaultCharset GBK
    IndexOptions Charset=GB2312

    DefaultIcon /icons/unknown.gif
    ForceLanguagePriority Prefer Fallback
    [root@TeLinux /root]$
    ```
    twl007
        6
    twl007  
       2018-04-30 15:41:06 +08:00 via iPhone
    我觉得你要去查查 Apache 文档 AllowOveride None 是不回去读.htacess 文件来修改你配置的 而且 80 跳 443 最好写到住配置文件里而不是在.htacess 里面
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1029 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:14 · PVG 04:14 · LAX 12:14 · JFK 15:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.