markdown 在ubuntu上设置ssl

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 在ubuntu上设置ssl相关的知识,希望对你有一定的参考价值。

Enable the module by typing:
```bash
sudo a2enmod ssl
```
After you have enabled SSL, you'll have to restart the web server for the change to be recognized:
```
sudo service apache2 restart
```
Let's start off by creating a subdirectory within Apache's configuration hierarchy to place the certificate files that we will be making:
```
sudo mkdir /etc/apache2/ssl
```
Now that we have a location to place our key and certificate, we can create them both in one step by typing:
```
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
```
The questions portion looks something like this:
```text
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:New York City
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Your Company
Organizational Unit Name (eg, section) []:Department of Kittens
Common Name (e.g. server FQDN or YOUR name) []:your_domain.com
Email Address []:your_email@domain.com
```
Open the file with root privileges now:
```
sudo nano /etc/apache2/sites-available/default-ssl.conf
```
With the comments removed, the file looks something like this:
```conf
<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                        SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                        SSLOptions +StdEnvVars
        </Directory>
        BrowserMatch "MSIE [2-6]" \
                        nokeepalive ssl-unclean-shutdown \
                        downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
    </VirtualHost>
</IfModule>
```
In the end, it will look something like this. The entries were modified from the original file:
```conf
<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerAdmin admin@example.com
        ServerName your_domain.com
        ServerAlias www.your_domain.com
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /var/www/html>
            SSLOptions +StdEnvVars
            DirectoryIndex index.php
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
        BrowserMatch "MSIE [2-6]" \
                        nokeepalive ssl-unclean-shutdown \
                        downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
    </VirtualHost>
</IfModule>
```
Save and exit the file when you are finished. Now that we have configured our SSL-enabled virtual host, we need to enable it.
```
sudo a2ensite default-ssl.conf
```
We then need to restart Apache to load our new virtual host file:
```
sudo service apache2 restart
```
That's it now run your site with https..!!

以上是关于markdown 在ubuntu上设置ssl的主要内容,如果未能解决你的问题,请参考以下文章

markdown 如何在Ubuntu服务器上设置Shadowsocks

markdown 在Intel Nuc上设置Ubuntu Web服务器,步骤和代码片段

markdown 编辑在Ubuntu服务器上设置qBittorrent作为带Web界面的守护进程(15.04及更高版本)

在 Ubuntu 14.04 上安装 Qt 5.5.1 - 在终端上抛出 qt.network.ssl 错误

markdown 在自定义PHP网站上启用SSL证书

在 xampp Apache Ubuntu 上设置 Certbot