一. 修改apache2原80端口为90端口
1. 修改/etc/apache2/ports.conf, 将端口80改为90,443,改为444
2. 修改/etc/apache2/sites-enabled/000-default, 将<virtualHost *:80>修改为90
3. 重启 service apache2 restart
 
 
二. 如果想访问多个虚拟主机,比如访问127.0.0.1:90和127.0.0.1:9001返回不同的内容
 
1. 在/etc/apache2/ports.conf中监听多个端口
 
2. 在/etc/apache2/sites-available中新建一个文件,例如test1.conf
运行命令a2ensite test1.conf ,使新建的配置文件生效
 
修改/etc/apache2/site-available的000-default.conf文件的DocumentRoot如下
 
 
3. 修改/etc/apache2/apache2.conf,注释掉Require这行,或者把denied改为granted
 
其实这一步不要也行,因为在下面还有一个默认的目录文件配置,已经赋予相应权限
 
 
4. 在/var/www/下新建目录html1,html2.  并在相应目录下新建index.html文件
然后重启apache,访问127.0.0.1:90和127.0.0.1:9001即可返回/var/www/html1,html2目录下的index.html内容
 
 
 
三. 端口转发
 
1. 首先配置mod_proxy模块
将/etc/apache2/mods-available中的proxy_http.load, proxy.load, proxy.conf, proxy_connect.load 软链接到/etc/apache2/mod2-enabled
 
2. 在/etc/apache2/site-enabled中建立一个文件,例如manage.conf
<VirtualHost *:8081>
        ServerName 127.0.0.1
        ProxyPass "/" "ajp://127.0.0.1:8009/"
        ProxyPassReverse / ajp://127.0.0.1:8009/
</VirtualHost>
 
这样访问本机的8081端口时,即可转发到tomcat中配置的ajp通道的8009端口
 
普通的http协议转发,比如我的阿里云上的tomcat,用80转发8088端口
<VirtualHost *:80>
        ServerName 127.0.0.1
        ProxyPass "/" "http://127.0.0.1:8088/"
        ProxyPassReverse / http://127.0.0.1:8088/
</VirtualHost>
 
 
 
 
 
四. 配置https访问
1. 安装openssl  apt-get install openssl
2. 开启SSL模块    a2enmod ssl
3. 创建一个自签名凭证
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
 
4. 编辑/etc/apache2/sites-availiable/default-ssl.conf
SSLEngin on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
 
5. 启用Apache缺省的SSL虚拟主机 a2ensite default-ssl
上面命令相当于ln -s /etc/apache2/sites-avaliable/default-ssl /etc/apache2/site-enabled/default-ssl
 
6. 重启apache2 即可
service apache2 restart
 
然后访问https://127.0.0.1即可,由于是自签名认证,网页会显示不安全提示,如果希望不提示该信息,那么可以导入证书(/etc/apache2/ssl/apache.crt)到受信任的根证书颁发机构。
 
 
 
如果想访问http时强制转为https访问
1. 在/etc/apache2/site-avaliable/000-default.conf中<virtualHost *:80>代码块中任意地方添加
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]
 
2. 启动rewrite mod
a2enmod rewrite
 
3. 重启apache
service apache2 restart
此时 访问http://127.0.0.1 即可自动跳转到https访问
 
参考:https://blog.csdn.net/positlive/article/details/54972990
 
 
 
 

ubuntu下apache2使用的简单总结的更多相关文章

  1. ubuntu下Apache2配置

    Ubuntu下Apache2的CGI简单配置:http://blog.csdn.net/a623891391/article/details/47170355 Ubuntu Apache的安装和配置以 ...

  2. Ubuntu下apache2安装配置(内含数字证书配置)

    Ubuntu下apache2安装配置(内含数字证书配置)安装命令:sudo apt-get updatesudo apt-get install apache2 配置1.查看apache2安装目录命令 ...

  3. Ubuntu 下 Apache2 和 PHP 服务器环境配置

    Ubuntu 下 Apache2 和 PHP 服务器环境配置 1.简介 本文主要是 Ubuntu 下 Apache2 和 PHP 服务器环境配置方法,同样适用于 Debian 系统:Ubuntu 20 ...

  4. ubuntu下apache2 安装 配置 卸载 CGI设置 SSL设置

    一.安装.卸载apache2      apache2可直接用命令安装           sudo apt-get install apache2      卸载比较麻烦,必须卸干净,否则会影响ap ...

  5. ubuntu下minicom安装和简单设置使用

    minicom是一个串口通信工具. Ubuntu下的安装: 打开终端 sudo apt-get install minicom即可完成安装. 简单设置使用: 安装完成后第一次启动时运行 sudo mi ...

  6. Ubuntu下安装MySQL及简单操作

    Ubuntu上安装MySQL非常简单只需要几条命令就可以完成. 1. sudo apt-get install mysql-server 2. apt-get isntall mysql-client ...

  7. Ubuntu 下apache2 增加新的module

    http://andrew913.iteye.com/blog/398648 首先来介绍下apache的一个工具apxs.apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,用于编译 ...

  8. Ubuntu下apache2启动、停止、重启、配置

    Linux系统为Ubuntu 一.Start Apache 2 Server /启动apache服务# /etc/init.d/apache2 startor$ sudo /etc/init.d/ap ...

  9. Ubuntu 下apache2开启rewrite隐藏index.php

    为了实现 http://www.example.com/route/route 而不是 http://www.example.com/index.php/route/route 需要开启apache2 ...

随机推荐

  1. Solr Dismax查询解析器-深入分析

    Solr 支持多种查询解析,给搜索引擎开发人员提供灵活的查询解析.Solr 中主要包含这几个查询解析器:标准查询解析器.DisMax 查询解析器,扩展 DisMax 查询解析器(eDisMax) Di ...

  2. Simple Style

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

  3. 简单API练手:(1)复制自身程序到windows目录和系统目录下;(2)获得系统的相关信息。

    1.复制自身程序到windows目录和系统目录下: #include <windows.h> #include <stdio.h> #include <string.h& ...

  4. java 线程之对象的同步和异步

    一.多线程环境下的同步与异步 同步:A线程要请求某个资源,但是此资源正在被B线程使用中,因为同步机制存在,A线程请求不到,怎么办,A线程只能等待下去. package com.jalja.org.th ...

  5. 使用 ipmitool 实现 Linux 系统下对服务器的 ipmi 管理

    http://www.ibm.com/developerworks/cn/linux/l-ipmi/ 1.简介 IPMI(Intelligent Platform Management Interfa ...

  6. 3-java_string学习笔记:

    java中String的常用方法

  7. 如何让局域网其他电脑通过IP直接访问自己电脑的网站

    具体方法如下: 1. 打开系统的控制面板 2. 打开控制面板后打开window防火墙. 3.点击图中的“高级设置”选项. 4.点击图中的“本地计算机上的高级安全 Windows 防火墙”在右侧点击“W ...

  8. Plupload 上传详细讲解,Plupload 多实例上传,Plupload多个上传按钮--推荐使用

    今天帮朋友解决  Plupload  上传的问题,查了很多资料,资料还是挺全的,但是有点零零散散的,故整理好,合并发出来. 本教程包括: Plupload  上传详细讲. Plupload  多实例上 ...

  9. swift学习之-- UIAlertViewController -alert

    // //  ViewController.swift //  alertView // //  Created by su on 15/12/7. //  Copyright © 2015年 tia ...

  10. ZOJ3767 Elevator 2017-04-13 23:32 37人阅读 评论(0) 收藏

    Elevator Time Limit: 2 Seconds      Memory Limit: 65536 KB How time flies! The graduation of this ye ...