Ubuntu 18.04配置 apache https 访问

2024-05-26 02:32

本文主要是介绍Ubuntu 18.04配置 apache https 访问,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

刚配置完一个 apache https,接下来 Ubuntu 18.04 服务器上也配置一个

Centos 7 配置 apache https访问以及Chrome 忽略证书错误继续

Ubuntu 18.04 缺省是安装了 apache2 ,并且安装了 ssl 模块!

$ apache2 -V

[Tue Aug 10 15:55:56.463588 2021] [core:warn] [pid 44253] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot
Server version: Apache/2.4.29 (Ubuntu)
Server built:   2021-06-18T11:06:22
  1. 直接打开 apache 首页,可以看到他的结构是这样子的

     /etc/apache2/|-- apache2.conf|       `--  ports.conf|-- mods-enabled|       |-- *.load|       `-- *.conf|-- conf-enabled|       `-- *.conf|-- sites-enabled|       `-- *.conf
    

    从字面就可以很清晰的看到各自的作用,注意端口的 Listen 单独放在了 ports.conf 文件中

  2. sites-enabled 站点缺省不带 https 的,但是 sites-available 中是存在的

    直接 ln 过来就好!

    $ cd /etc/apache2/sites-enabled

    $ sudo ln …/sites-available/default-ssl.conf .

    以为和刚才 centos 下一样,什么都不用改了!直接测试一下

  3. 直接测试一下
    $ curl -k https://127.0.0.1
    不通!

  4. ubuntu 还要 enable 这个 ssl 模块!

    $ sudo a2enmod ssl

    Considering dependency setenvif for ssl:
    Module setenvif already enabled
    Considering dependency mime for ssl:
    Module mime already enabled
    Considering dependency socache_shmcb for ssl:
    Enabling module socache_shmcb.
    Enabling module ssl.
    See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
    To activate the new configuration, you need to run:
    systemctl restart apache2

  5. 再来测试

    $ systemctl restart apache2

    $ curl -k https://127.0.0.1

    假设映射的外网地址是 12.34.56.78,端口是 4433
    因为 443 一般会被nginx 占用了

    $ curl -k https://12.34.56.78:4433/

    也会有证书错误警告!

     curl: (60) SSL certificate problem: self signed certificateMore details here: https://curl.haxx.se/docs/sslcerts.htmlcurl failed to verify the legitimacy of the server and therefore could notestablish a secure connection to it. To learn more about this situation andhow to fix it, please visit the web page mentioned above.
    

    都可以访问了!

  6. Chrome 还会出现证书错误,记住 thisisunsafe 就好!

限制 ip 访问

$ cd /etc/apache2

$ sudo vim apache2.conf

找到需要限制访问的网站目录
假设 允许 2 个外网地址 12.34.56.78 和 1.2.3.4

...
<Directory /var/www/>Options Indexes FollowSymLinksAllowOverride NoneRequire all granted# wzh 20210810Order Deny,AllowDeny From allAllow From 127.0.0.1Allow From 192.168.0.0/24Allow From 1.2.2.3Allow From 12.34.56.78
</Directory>
...

如果想加黑名单,就直接去 hosts.deny 吧!

重启生效
$ sudo systemctl restart apache2

测试

  1. 不在允许名单内

$ curl XXX.XXX.XXX.XXX

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<hr>
<address>Apache/2.4.29 (Ubuntu) Server at XXX.XXX.XXX.XXX Port 80</address>
</body></html>
  1. 本机测试

    $ curl 127.0.0.1

  2. 内网测试

    $ curl 192.168.0.123

这篇关于Ubuntu 18.04配置 apache https 访问的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1003304

相关文章

Spring配置扩展之JavaConfig的使用小结

《Spring配置扩展之JavaConfig的使用小结》JavaConfig是Spring框架中基于纯Java代码的配置方式,用于替代传统的XML配置,通过注解(如@Bean)定义Spring容器的组... 目录JavaConfig 的概念什么是JavaConfig?为什么使用 JavaConfig?Jav

Spring Boot Interceptor的原理、配置、顺序控制及与Filter的关键区别对比分析

《SpringBootInterceptor的原理、配置、顺序控制及与Filter的关键区别对比分析》本文主要介绍了SpringBoot中的拦截器(Interceptor)及其与过滤器(Filt... 目录前言一、核心功能二、拦截器的实现2.1 定义自定义拦截器2.2 注册拦截器三、多拦截器的执行顺序四、过

springboot的controller中如何获取applicatim.yml的配置值

《springboot的controller中如何获取applicatim.yml的配置值》本文介绍了在SpringBoot的Controller中获取application.yml配置值的四种方式,... 目录1. 使用@Value注解(最常用)application.yml 配置Controller 中

springboot中配置logback-spring.xml的方法

《springboot中配置logback-spring.xml的方法》文章介绍了如何在SpringBoot项目中配置logback-spring.xml文件来进行日志管理,包括如何定义日志输出方式、... 目录一、在src/main/resources目录下,也就是在classpath路径下创建logba

C++多线程开发环境配置方法

《C++多线程开发环境配置方法》文章详细介绍了如何在Windows上安装MinGW-w64和VSCode,并配置环境变量和编译任务,使用VSCode创建一个C++多线程测试项目,并通过配置tasks.... 目录下载安装 MinGW-w64下载安装VS code创建测试项目配置编译任务创建 tasks.js

Nginx概念、架构、配置与虚拟主机实战操作指南

《Nginx概念、架构、配置与虚拟主机实战操作指南》Nginx是一个高性能的HTTP服务器、反向代理服务器、负载均衡器和IMAP/POP3/SMTP代理服务器,它支持高并发连接,资源占用低,功能全面且... 目录Nginx 深度解析:概念、架构、配置与虚拟主机实战一、Nginx 的概念二、Nginx 的特点

SpringBoot整合Apache Spark实现一个简单的数据分析功能

《SpringBoot整合ApacheSpark实现一个简单的数据分析功能》ApacheSpark是一个开源的大数据处理框架,它提供了丰富的功能和API,用于分布式数据处理、数据分析和机器学习等任务... 目录第一步、添加android依赖第二步、编写配置类第三步、编写控制类启动项目并测试总结ApacheS

2025最新版Android Studio安装及组件配置教程(SDK、JDK、Gradle)

《2025最新版AndroidStudio安装及组件配置教程(SDK、JDK、Gradle)》:本文主要介绍2025最新版AndroidStudio安装及组件配置(SDK、JDK、Gradle... 目录原生 android 简介Android Studio必备组件一、Android Studio安装二、A

前端Visual Studio Code安装配置教程之下载、汉化、常用组件及基本操作

《前端VisualStudioCode安装配置教程之下载、汉化、常用组件及基本操作》VisualStudioCode是微软推出的一个强大的代码编辑器,功能强大,操作简单便捷,还有着良好的用户界面,... 目录一、Visual Studio Code下载二、汉化三、常用组件1、Auto Rename Tag2

Apache服务器IP自动跳转域名的问题及解决方案

《Apache服务器IP自动跳转域名的问题及解决方案》本教程将详细介绍如何通过Apache虚拟主机配置实现这一功能,并解决常见问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,... 目录​​问题背景​​解决方案​​方法 1:修改 httpd-vhosts.conf(推荐)​​步骤