apache2的端口配置不同于apache,没有httpd.conf 这个文件。
而是一般在 /etc/apache2/ports.conf 添加监听端口,在 /etc/apache2/sites-enabled/ 下面新加端口对应的路径。
ports.conf 增加Listen的端口
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80
Listen 8009
Listen 8006
在 /etc/apache2/sites-enabled/ 下面新加8006.conf
<VirtualHost *:8006>
# 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/me
# 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>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
![](https://i-blog.csdnimg.cn/blog_migrate/9dfa60d54b29e2d21c9c37ea74340b8e.png)
其他一些apache2设置小细节:
打开网站目录显示:
<Directory />
OptionsIndexes FollowSymLinks #这样就可以让网站显示目录结果了.
# Options FollowSymLinks # 这样是网站关闭网站显示目录
AllowOverride All
</Directory>
重启apache服务:
apahce启动命令:
推荐/usr/local/apache2/bin/apachectl start apaceh启动
apache停止命令
/usr/local/apache2/bin/apachectl stop 停止
apache重新启动命令:
/usr/local/apache2/bin/apachectl restart 重启