Update from Sync Service
This commit is contained in:
@@ -1,21 +1,153 @@
|
||||
1. 首先,安装Apache2,安装命令:sudo apt-get install apache2
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=1)3. 安装完成后,进入到/etc/apache2中(根据自己的实际安装目录),这边我配置文件在/etc/apache2中。 我们看到没有想象中的httpd.conf配置文件,这里要说明的是apache2的配置文件是apache2.conf,而不是http.conf。 打开apache2.conf。写入两条语句ServerName localhostDirectoryIndex index.html index.htm index.php这里的ServerName localhost是为了防止最后开启apache2服务的时候会提示DNS出错。DirectoryIndex index.html index.htm index.php是默认目录的写法。保存退出。可以在apache2.conf中加入 AddDefaultCharset GB2312  设置默认字符集,定义服务器返回给客户机默认字符集(由于西欧UTF-8是Apache默认字符集,因此当访问有中文的网页时会出现乱码,这时只要将字符集改成GB2312,再重启Apache服务即可)Listen 192.168.1.1:80 设置监听ip是192.168.1.1的地址和端口为80Listen 192.168.1.2:8080 设置监听ip是192.168.1.2的地址和端口为8080Alias /down "/sofТWare /download" 创建虚拟目录(创建名为down的虚拟目录,它对应的物理路径是:/sofТWare /download)Alias /ftp "/var/ftp" 创建虚拟目录(创建名为ftp的虚拟目录,它对应的物理路径是:/var/ftp)<Directory "/var/www/html"> 设置目录权限(<Directory "目录路径">此次写设置目录权限的语句</Directory>) Options FollowSymLinks page:116 AllowOverride None</Directory>
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=2)
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=3)7. 需要说明的是,在apache2中,根设置(默认主目录)在 /etc/apache2/sites-АVailable/default中,我们打开default,进行配置。如图,这里我们的默认主目录设置的路径是/var/www,文档最上方的VirtualHost后方的*代表通配符,即表示所有本机ip地址,监听端口为80,ServerName填写你注册的域名,没有可以不填。保存退出。
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=4)
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=5)11. 至此,基本配置已经全部完成,查看本机ip地址。输入启用apache2的命令:/etc/init.d/apache2 restart.并在浏览器中输入本机ip地址。成功!
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=6)
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=7)
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=8)
|
||||
# 阿里云配置 Apache
|
||||
|
||||
## END
|
||||
注意事项
|
||||
> Ubuntu Apache2 配置指南
|
||||
|
||||
18. 配置文件从httpd.conf变成了apache2.con > 来自 <[https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html](https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html)>
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=1)[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=2)
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=3)[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=4)
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=5)[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=6)
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=7)
|
||||
[](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=8)
|
||||
> 来自 <[https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html](https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html)>
|
||||

|
||||
---
|
||||
|
||||
## 安装 Apache
|
||||
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install apache2 -y
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 配置文件
|
||||
|
||||
### 重要文件位置
|
||||
|
||||
| 文件 | 说明 |
|
||||
|------|------|
|
||||
| `/etc/apache2/apache2.conf` | 主配置文件 |
|
||||
| `/etc/apache2/sites-available/` | 站点配置目录 |
|
||||
| `/etc/apache2/sites-enabled/` | 已启用站点 |
|
||||
| `/etc/apache2/ports.conf` | 端口配置 |
|
||||
|
||||
> ⚠️ **注意**:Apache2 用 `apache2.conf`,不是传统的 `httpd.conf`
|
||||
|
||||
---
|
||||
|
||||
## 基本配置
|
||||
|
||||
### 1. 配置 apache2.conf
|
||||
|
||||
```bash
|
||||
sudo vim /etc/apache2/apache2.conf
|
||||
```
|
||||
|
||||
添加:
|
||||
```apache
|
||||
ServerName localhost
|
||||
DirectoryIndex index.html index.htm index.php
|
||||
```
|
||||
|
||||
### 2. 设置默认字符集
|
||||
|
||||
```apache
|
||||
AddDefaultCharset UTF-8
|
||||
```
|
||||
|
||||
### 3. 设置监听端口
|
||||
|
||||
```apache
|
||||
Listen 80 # 监听 80 端口
|
||||
Listen 8080 # 监听 8080 端口
|
||||
```
|
||||
|
||||
### 4. 创建虚拟目录
|
||||
|
||||
```apache
|
||||
Alias /down "/software/download"
|
||||
Alias /ftp "/var/ftp"
|
||||
```
|
||||
|
||||
### 5. 设置目录权限
|
||||
|
||||
```apache
|
||||
<Directory "/var/www/html">
|
||||
Options FollowSymLinks
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 配置站点
|
||||
|
||||
### 1. 编辑默认站点
|
||||
|
||||
```bash
|
||||
sudo vim /etc/apache2/sites-available/000-default.conf
|
||||
```
|
||||
|
||||
```apache
|
||||
<VirtualHost *:80>
|
||||
ServerName yourdomain.com
|
||||
ServerAlias www.yourdomain.com
|
||||
DocumentRoot /var/www/html
|
||||
|
||||
<Directory /var/www/html>
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
</VirtualHost>
|
||||
```
|
||||
|
||||
### 2. 启用站点
|
||||
|
||||
```bash
|
||||
sudo a2ensite 000-default.conf
|
||||
sudo a2enmod rewrite
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 常用命令
|
||||
|
||||
```bash
|
||||
# 启动/停止/重启
|
||||
sudo systemctl start apache2
|
||||
sudo systemctl stop apache2
|
||||
sudo systemctl restart apache2
|
||||
|
||||
# 或
|
||||
sudo /etc/init.d/apache2 start
|
||||
sudo /etc/init.d/apache2 restart
|
||||
|
||||
# 查看状态
|
||||
sudo systemctl status apache2
|
||||
|
||||
# 启用/禁用站点
|
||||
sudo a2ensite site-name
|
||||
sudo a2dissite site-name
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 测试配置
|
||||
|
||||
```bash
|
||||
# 测试配置文件语法
|
||||
sudo apache2ctl configtest
|
||||
|
||||
# 查看已启用模块
|
||||
apache2ctl -M
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 安全建议
|
||||
|
||||
1. 禁用不必要的模块
|
||||
2. 隐藏 Apache 版本信息
|
||||
3. 启用 HTTPS (Let's Encrypt)
|
||||
4. 配置防火墙只开放 80/443
|
||||
|
||||
---
|
||||
|
||||
> 参考:[百度经验 - Ubuntu Apache2 配置](https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html)
|
||||
|
||||
Reference in New Issue
Block a user