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

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

安装

命令:
sudo apt-get update
sudo apt-get install apache2
在这里插入图片描述

配置

1、查看apache2安装目录

命令:whereis 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保存退出。

在这里插入图片描述

4、启动apache2

启动命令:sudo service apache2 start 或者 sudo /etc/apache2 start
查看状态命令:sudo /etc/apache2 status 或者 netstat -ap|grep 9080
在这里插入图片描述
启动成功,访问测试
在这里插入图片描述

**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 或者 sudo /etc/init.d/apache2 restart

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值