Home  >  Q&A  >  body text

Apache server enables HTTPS access

Currently, Apache is installed on a Centos, and three virtual machines are created, one of which is configured with an SSL service. The effect I want is to disable HTTP access and only allow HTTPS access. How to configure and implement this?

Current situation: Both HTTP and HTTPS can be accessed.

PHP中文网PHP中文网2713 days ago624

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 17:03:15

    Do you want to force http to jump to https access, or do you want http to be directly set to be inaccessible? Generally, websites that deploy https will take into account that users are accustomed to http input, and will configure the server to force http to jump to https. The Apache server configuration is as follows:
    If you need to jump to the entire site, then in the <Directory> tag of the website's configuration file , type the following:

    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)?$ https://%{SERVER_NAME}/ [L,R]
    

    If you want to force https redirect to a certain directory, copy the following code:

    RewriteEngine on
    RewriteBase /yourfolder
    RewriteCond %{SERVER_PORT} !^443$
    #RewriteRule ^(.*)?$ https://%{SERVER_NAME}/ [L,R]
    RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-16 17:03:15

    Just delete the virtual host corresponding to the http you configured.
    https is a virtual host configured with ssl, so the original http configuration has no impact on it

    reply
    0
  • Cancelreply