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

Ubuntu下apache2安装配置(内含数字证书配置)
安装
命令:
sudo apt-get update
sudo apt-get install apache2

Ubuntu下apache2安装配置(内含数字证书配置)
配置
1、查看apache2安装目录
命令:whereis apache2
如图

Ubuntu下apache2安装配置(内含数字证书配置)
2、apache2配置文件所在目录/etc/apache2,以下是对配置文件的作用以及作用域
注1:/etc/apache2/apache2.conf 是主配置文件
注2:/etc/apache2/ports.conf 始终包含在主配置文件中(用于确定传入连接的监听端口,默认为80,可重新配置端口)
注3:其它配置文件在/etc/apache2/sites-enabled、/etc/apache2/conf-enabled、/etc/apache2/mods-enabled目录下。
注4:apache2的默认web目录:/var/www/html(在/etc/apache2/sites-enabled/000-default.conf 里可以看到这个 DocumentRoot /var/www/html 配置)
注5:apache2 的默认用户是 www-data,定义在 /etc/apache2/envvars 文件中
注6:设置默认主页的配置文件/etc/apache2/mods-enabled/dir.conf

3、修改端口(此处修改的是监听端口)
命令:sudo vi /etc/apache2/ports.conf
insert进入编辑状态,修改端口,按键ESC,输入:wq保存退出。

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

4、启动apache2
启动命令:sudo service apache2 start 或者 sudo /etc/apache2 start
查看状态命令:sudo /etc/apache2 status 或者 netstat -ap|grep 9080

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

启动成功,访问测试

Ubuntu下apache2安装配置(内含数字证书配置)
**5、配置虚拟机
需要访问自己的项目,就需要配置虚拟主机,可配置多域名多端口,此处只配置一个,谢谢
此处是直接在/etc/apache2/apache2.conf中添加下面配置的

# VirtualHost后加端口
<VirtualHost *:443>
# 网站内容的目录路径,即是项目前端文件所在目录
DocumentRoot "/mnt/home/shzj_web/" # 设置数字证书
SSLEngine On
SSLOptions +StrictRequire
SSLCertificateFile /mnt/home/ssl/xxxxxx.pem # 证书公钥配置
SSLCertificateKeyFile /mnt/home/ssl/xxxxxx.key # 证书私钥配置 # 在ServerName后加上域名
ServerName 域名
ProxyPreserveHost On # 跨域问题解决设置
# 反向代理指向api,v1为后台访问的某段固定地址
ProxyPass /v1/ http://域名:9083/v1/ timeout=300
ProxyPassReverse /v1/ http://域名:9083/v1/ timeout=300
# 修饰目录访问属性
<Directory "/mnt/home/shzj_web/">
AllowOverride All
RewriteEngine On
RewriteBase "/"
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
Options Indexes FollowSymLinks
Require all granted
</Directory> </VirtualHost>

  

6、重启apache2
命令: sudo service apache2 restart 或者 sudo /etc/apache2 restart

至此,apache安装配置完成!!!

上一篇:SDAU课程练习--problemA(1000)


下一篇:centos6.5 命令行配置无线上网