apache与nginx的简单对比
可以nginx做前端文件显示, apache做后端动态处理
| Apache |
Nginx |
| 稳定, 动态请求处理强 |
擅长静态请求处理 |
| 高并发时性能弱, 耗费资源多 |
高并发能力强, 擅长反向处理, 负载均衡, 内存占用少 |
编译安装apache
yum安装apache的目录解析
折叠代码块YML
复制代码
1 2 3 4
| /usr/local/bin: 存放可执行文件 /usr/local/lib: 存放库文件 /usr/local/etc: 存放配置文件 /usr/local/share: 存放其他资源文件
|
源码编译步骤
折叠代码块YML
复制代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| 配置: configure,依赖于gcc编译器,binutils,glibc。此步骤会配置软件特性,检查编译环境,生成Makefile文件 编译: make 安装: make install ```
1. 编译安装可以自定义编译参数, 提高性能 2. 解决不必要的软件依赖 3. 方便清理(直接删除目录, 或在安装目录`make uninstall`)与数据迁移(可以直接复制编译的目录到其他机器)
1. httpd依赖于apr(apache portable runtime), apr-util 2. httpd-2.4依赖apr1.4+
```bash
yum install gcc yum install pcre-devel yum install binutils yum install glibc yum install openssl-devel
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.5.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.37.tar.gz
tar -zxvf apr-1.6.5.tar.gz tar -zxvf apr-util-1.6.1.tar.gz tar -zxvf httpd-2.4.37.tar.gz
cd apr-1.6.5 ./configure --prefix=/usr/local/apr make && make install
cd ../apr-util-1.6.1 ./configure \ --prefix=/usr/local/apr-util \ --with-apr=/usr/local/apr make && make install
yum install expat-devel
cd ../httpd-2.4.37 ./configure \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util \ --prefix=/usr/local/apache \ --sysconfdir=/etc/httpd24 \ --enable-so \ --enable-ssl \ --enable-cgi \ --enable-rewrite \ --with-zlib \ --with-pcre \ --with-mpm=prefork \ --enable-modules=most \ --enable-mpms-shared=all make && make install
|
更改apache相关配置
文件根目录
找到配置文件, 一般在/etc/apache或/etc/httpd之类的文件夹里
折叠代码块BASH
复制代码
1 2
| cd /etc/apache2 vim apache2.conf
|
修改目录为自己的自定义目录
折叠代码块XML
复制代码
1 2 3 4 5 6 7 8 9
| <Directory /home/deepin/Workspace/htmls> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
DocumentRoot "/var/www"
|
修改后重启apache
折叠代码块BASH
复制代码
1
| sudo service apache2 restart
|
端口
找到配置文件, 一般在/etc/apache或/etc/httpd之类的文件夹里
折叠代码块BASH
复制代码
1 2
| cd /etc/apache2 vim ports.conf
|
修改Listen为需要的端口
修改后重启apache
折叠代码块BASH
复制代码
1
| sudo service apache2 restart
|
关闭和开启apache2开机自启动
折叠代码块BASH
复制代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| update-rc.d -f apache2 remove
update-rc.d apache2 defaults ``` 如实在关不掉, 可以在系统的自启动脚本里添加`service apache2 stop` [参考](https://blog.csdn.net/chen200910a/article/details/22089267)
```bash
su root vi /opt/lampp/etc/httpd.conf
CustomLog "logs/access_log" combined
source /root/.bash_profile xampp reload
|
v1.5.2