Shared Hosting in SSL with VirtualDocumentRoot

I am working on my work on ubuntu 16.04 VM

When I work on several projects to simplify my life, I use VirtualDocumentRoot and the hosts file on server sites from my home folder using .dev domains:

In 000-default.conf, I have:

<VirtualHost *:80>
  VirtualDocumentRoot  /home/steve/websites/%-2/%-2/public_html
  ServerAlias *.dev
</VirtualHost>

then on the hosts I have various sites I'm working on:

127.0.0.1   somesite.dev
127.0.0.1   another.dev
127.0.0.1   athirdone.dev
127.0.0.1   blog.athirdone.dev

Thus, when I add a new project, I just need to create the correct folder structure in the sites directory and add a line to the hosts, for example, if I want to work on a new project somecoolproject.dev, I just add a folder:

/home/steve/websites/somecoolproject/somecoolproject/public_html

and line in hosts:

127.0.0.1    somecoolproject.dev

And I'm good to go.

, , , https, , , htaccess .., dev.

dev , , - *.dev .

, , - , , .

+4
2

, :

  • SSL- *.dev
  • apache , *.dev SSL/TLS *.dev.

, , , .

: SNI- , TLS, TLS, HTTP- (, ), -, , - .

:

. :

mindaugas@mindaugas-ubuntu-14:/usr/local/apache2/conf$ sudo openssl req        -newkey rsa:2048 -nodes -keyout domain.key -x509 -days 365 -out domain.crt
Generating a 2048 bit RSA private key
.............+++
..................+++
writing new private key to 'domain.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:*.dev
Email Address []:

:

Common Name (e.g. server FQDN or YOUR name) []:*.dev

.

:

Listen 443

<VirtualHost *:443>
  SSLEngine on
  SSLCertificateFile "/usr/local/apache2/conf/domain.crt"
  SSLCertificateKeyFile "/usr/local/apache2/conf/domain.key"

  VirtualDocumentRoot /home/mindaugas/websites/%-2/pubic/
  ServerAlias *.dev
  <Directory "/">
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Allow from All
      Require all granted
  </Directory>
</VirtualHost>

ssl apache:

sudo a2enmod ssl
sudo service apache2 restart

:

  • ;
  • HTML-;
  • - ip , , " " :

enter image description here

+1

, , . - , VirtualDocumentRoot SSL. SSL , ssl. , .

: 1/ ( , ), , 2/ httpd.conf Include /httpd -ssl.conf

httpd-ssl.conf conf ( ):

UseCanonicalName Off
ProxyPreserveHost  On

SetEnvIf  Server_Addr "(.*)"  sname=$1

RewriteEngine   On
RewriteCond     "%{HTTPS}" =on
RewriteRule     ^/(.*)$ "http://%{ENV:sname}:80/$1" [P]

, , . , , SSL SSL . httpd.conf , LogFormat, :

LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" enhanced
LogFormat "%V %h %l %u %t \"%r\" %>s %b" enhancedSSL
CustomLog "logs/access_log" enhanced

httpd-ssl.conf, :

CustomLog "logs/access_log" enhancedSSL

, . , , , SSL, , . , 80 () VirtualHost (VirtualHost 127.0.0.1:80 *: 80).

+1

Source: https://habr.com/ru/post/1691975/


All Articles