Httpd服务入门知识-Httpd服务常见配置案例之修改监听的IP和Port
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.查看默认配置
[[email protected] ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd"
Listen
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
[[email protected] ~]#
二.修改监听的IP和Port语法
Listen [IP:]PORT
()省略IP表示为本机所有IP
()Listen指令至少一个,可重复出现多次
三.修改监听的IP地址和Port实战案例
[[email protected] ~]# ss -ntl #默认监听本机的所有IP地址的80端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:*
LISTEN *: *:*
LISTEN ::: :::*
[[email protected] ~]#
[[email protected] ~]# vim /etc/httpd/conf.d/listen.conf
[[email protected] ~]#
[[email protected] ~]# cat /etc/httpd/conf.d/listen.conf #我们可以配置多条listen指令,它们并不会相互影响哟~
listen
listen 172.30.1.101:
[[email protected] ~]#
[[email protected] ~]# httpd -t
Syntax OK
[[email protected] ~]#
[[email protected] ~]# systemctl reload httpd
[[email protected] ~]#
[[email protected] ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:*
LISTEN *: *:*
LISTEN *: *:*
LISTEN 172.30.1.101: *:*
LISTEN ::: :::*
[[email protected] ~]#
[[email protected] ~]#