Ubuntu安装Apache2
一、安装
1.安装
sudo apt-get install apache2
2.卸载
sudo apt-get purge apache2
二、常用命令
1.启动
sudo systemctl start apache2
2.停止
sudo systemctl stop apache2
3.重启
sudo systemctl restart apache2
4.状态
sudo systemctl status apache2
5.查看版本
apachectl –v
6.校验配置是否正确
apachectl configtest
三、工作模式切换(默认为event最好)
1.停止运行apache2
sudo systemctl stop apache2
2.查看所有MPM模块
ls /etc/apache2/mods-available/mpm*
3.查看启动的模块
ls -l /etc/apache2/mods-enabled/mpm*
4.禁用启用的模块
a2dismod mpm_event
5.启动worker模块
a2enmod mpm_worker actions rewrite
6.启动运行
sudo systemctl start apache2
7.检查是否运行worker模块
apachectl -V | grep -i mpm
四、工作模式参数说明
1.参数修改位置
<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 0
</IfModule>
2.参数说明
StartServers:服务器启动时建立的子进程数量.
ServerLimit:系统配置的最大进程数量
MinSpareThreads:空闲子进程的最小数量
MaxSpareThreads:空闲子进程的最大数量
ThreadsPerChild:每个子进程产生的线程数量
MaxRequestWorkers / MaxClients:限定服务器同一时间内客户端最大接入的请求数量.
MaxConnectionsPerChild:每个子进程在其生命周期内允许最大的请求数量,如果请求总数已经达到这个数值,子进程将会结束,如果设置为0,子进程将永远不会结束。在Apache2.3.9之前称之为MaxRequestsPerChild。
五、模块添加
1.所有模块查看
ls /usr/lib/apache2/modules/
2.apache2.conf最后添加加载代码
六、SSL配置
1.查看默认模块目录
ls /usr/lib/apache2/modules/
2.进入apache2安装目录,打开配置文件
3.最后一行添加SSL依赖
LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so
4.修改监听端口
vim ports.conf
5.进入sites-enabled/目录修改000-default.conf文件
<VirtualHost *:7080>
# 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 www.example.com
ServerAdmin webmaster@localhost
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
</VirtualHost>
<VirtualHost _default_:7443>
Redirect / http://10.22.85.95:8080/
# 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
SSLEngine On
# 证书文件的路径(需要自己申请,或找IT部门的同事要)
SSLCertificatefile "xxxx.crt"
# key文件的路径(需要自己申请,或找IT部门的同事要)
SSLCertificateKeyfile "xxxx.key"
</VirtualHost>
6.校验配置
sudo apachectl configtest
7.启动SSL服务
sudo a2enmod ssl
8.启动apace2
sudo systemctl start apache2
赞(1)
赏