前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用公网CA部署内网https网站

使用公网CA部署内网https网站

作者头像
羽翰尘
修改2019-11-26 16:37:42
1.6K0
修改2019-11-26 16:37:42
举报
文章被收录于专栏:技术向技术向技术向

本文由腾讯云+社区自动同步,原文地址 https://stackoverflow.club/article/set_https_for_local_network/

简介

有时候内部网络不能对公网开放(即使有登陆限制),又不希望网站内容被嗅探。使用https技术可以实现网站与浏览器的内容加密,但是根证书机构无法访问内网服务器。

大多数内网https的实现方案是用自签证书,所有浏览器需要添加根证书,在使用上存在困难。

思路

利用手头的公网服务器,先将域名放到公网服务器上,签过证书后再解析到内网服务器。

步骤

1. 创建公网网站

到域名服务商处修改域名指向到公网服务器,网站指向默认路径,内容可有可无。

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName icloud.stackoverflow.club
        ServerAdmin wenfengand@gmail.com
        DocumentRoot /var/www/html
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        #This section is written by the apache gui do not manually edit apacheguilogholder
        LogFormat "%h\",\"%{User-agent}i\",\"%r\",\"%>s\",\"%B" apacheguilogholder
        CustomLog "|\"/usr/bin/java\" -jar \"/home/ubuntu/download/ApacheGUI/tomcat/bin/LogParser.jar\" \"/home/ubuntu/download/ApacheGUI/tomcat\"" apacheguilogholder
</VirtualHost>

2. 生成证书

在命令行输入

certbot

会有对话框出现,选择要签名的域名,并设置跳转。

3. 拷贝文件到内网

/etc/letsencrypt/live/icloud.stackoverflow.club/文件夹和/etc/letsencrypt/options-ssl-apache.conf拷贝到内网服务器,我这里是将所有文件放到了内网服务器的/home/pi/workspace/icloud.stackoverflow.club/目录。

/etc/apache2/sites-available/icloud-le-ssl.conf拷贝到内网服务器对应目录。

4. 更新内网网站配置

内网服务器可能需要激活一些模块

sudo a2enmod rewrite
sudo a2enmod ssl

修改icloud-le-ssl.conficloud.conf使其符合自身需求。

启用https

sudo a2ensite icloud-le-ssl.conf`

将下述配置添加到http的conf文件中,实现http跳转https

RewriteEngine on
RewriteCond %{SERVER_NAME} =icloud.stackoverflow.club
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

重启apache

sudo service apache2 restart

在域名服务商处改回原有DNS配置,稍等片刻,检查https是否配置成功。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-07-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简介
  • 思路
  • 步骤
    • 1. 创建公网网站
      • 2. 生成证书
        • 3. 拷贝文件到内网
          • 4. 更新内网网站配置
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档