Apache2.4監聽多端口
參考:ArchWiki
https://wiki.archlinux.org/index.php/Apache_HTTP_Server
一個ip
配置多個端口的web服務
,Apache2
的配置目錄在/etc/apache2
,打開文件看一下內容和註釋,改一改模板就可以了(沒有找到完整的配置過程,配置新版本的軟件往往需要自己動手)
修改的文件 :
/etc/apache2/apache2.conf
/etc/apache2/ports.conf
/etc/apache2/sites-available/000-default.conf
配置web的根目錄 :/data/www
web服務端口 :8081
shell如下:
##### VirtualHost #####
mkdir -p /data/www && \
chmod -R 777 /data/www && \
cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak && \
sed -i '/#<Directory \/srv\/>/i\<Directory /data/www/>\n\tOptions Indexes FollowSymLinks\n\tAllowOverride All\n\tRequire all granted\n</Directory>' /etc/apache2/apache2.conf && \
cp /etc/apache2/ports.conf /etc/apache2/ports.conf.bak && \
sed -i '/^Listen/a\Listen 8081' /etc/apache2/ports.conf && \
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf.bak && \
echo "<VirtualHost *:8081>
ServerAdmin webmaster@localhost
DocumentRoot /data/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
" >> /etc/apache2/sites-available/000-default.conf && \
/etc/init.d/apache2 restart && \
echo "<?php phpinfo(); ?>" > /data/www/index.php && \
chmod 755 /data/www/index.php && \
curl 127.0.0.1:8081
##### VirtualHost #####
apache2與httpd
apache2
默認用戶組 : www-data:www-data
(cat /etc/group | grep www)
httpd
默認用戶組 : apache:apache
權限設置參考:
chgrp -R www-data /data/www && \
find /data/www -type d -exec chmod g=rwxs "{}" \; && \
find /data/www -type f -exec chmod g=rw "{}" \;