- 環境說明
Ubuntu 16.04 LTS
- 安裝軟件
安裝apache2:
apt-get install apache2
配置以后不升級:
apt-mark hold apache2
- 配置
創建/etc/apache2/conf-available/http-fileserver.conf配置文件,內容以下:
<Directory /data/http_files> 配置文件存儲目錄
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
Require all granted
</Directory>
鏈接到conf-enabled目錄:
ln -s /etc/apache2/conf-available/http-fileserver.conf /etc/apache2/conf-enabled/http-fileserver.conf
創建/etc/apache2/sites-available/http-fileserver-site.conf配置文件,內容如下:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /data/http_files 指定文件存儲根目錄
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
鏈接到sites-enabled目錄:
ln -s /etc/apache2/sites-available/http-fileserver-site.conf /etc/apache2/sites-enabled/http-fileserver-site.conf
刪除默認虛擬主機配置文件:
rm /etc/apache2/sites-enabled/000-default.conf
- 創建目錄及修改權限
mkdir -p /data/http_files
chmod -R 755 /data/http_files
- 重啟apache2服務器
service apache2 restart
- 附最簡配置
# vim /etc/apache2/sites-enabled/000-default.conf
DocumentRoot /var/www
# /etc/init.d/apache2 restart