Ste*_*eve 5 apache ubuntu ssl virtualhost
我在ubuntu 16.04 VM上进行开发工作
当我处理许多项目时,为了让我的生活更轻松,我使用*.dev域将VirtualDocumentRoot和hosts文件从我的主文件夹中用于服务器站点:
在000-default.conf我有:
<VirtualHost *:80>
VirtualDocumentRoot /home/steve/websites/%-2/%-2/public_html
ServerAlias *.dev
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
然后在主机中我有我正在研究的各种网站:
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
Run Code Online (Sandbox Code Playgroud)
这样,当我添加一个新项目时,我只需要在网站目录中创建正确的文件夹结构并向主机添加一行,例如,如果我想处理一个新项目somecoolproject.dev,我只需添加一个文件夹:
/home/steve/websites/somecoolproject/somecoolproject/public_html
Run Code Online (Sandbox Code Playgroud)
和主机中的一行:
127.0.0.1 somecoolproject.dev
Run Code Online (Sandbox Code Playgroud)
我很高兴去.
无论如何,我现在工作的几乎所有内容都运行在https上,并且许多项目都有代码来强制执行此操作,无论是在源代码还是htaccess等,这使得处理开发副本变得很麻烦.
我想在我的开发机器上创建一个自签名证书,理想情况是我不需要为每个项目生成一个新的证书,所以某种通配符*.dev会很棒.
但即使我确实需要为每个项目创建一个新项目,我仍然无法解决如何使用我的设置安装它 - 我找到的所有内容都假设一个固定文档和硬编码的服务器名称.
如果我正确理解了要求,您想知道:
如果我理解正确的话,这当然是可行的。
它将如何工作:SNI - 服务器名称指示,TLS 协议扩展,其中在建立 TLS 连接时传递主机名,在 HTTP 数据(如主机标头)可用之前传递。所有流行的网络浏览器、curl、所有流行的网络服务器都支持它。
脚步:
第一的。生成证书:
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 []:
Run Code Online (Sandbox Code Playgroud)
关键部分是:
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>
Run Code Online (Sandbox Code Playgroud)
启用 ssl 并重新启动 apache:
sudo a2enmod ssl
sudo service apache2 restart
Run Code Online (Sandbox Code Playgroud)
您可以通过以下方式进行测试:
| 归档时间: |
|
| 查看次数: |
667 次 |
| 最近记录: |