centos

apache监听端口

如何监听http请求?
如何监听https请求?
如何把http请求重定向为https请求?
如何监听多个域名的请求?
记录 apache 常用命令

监听http请求

在/etc/httpd/conf.d/目录下新建文件:vhost.conf 用来配置监听80端口

NameVirtualHost *:80
# 把域名godpython.com 80端口请求重定向到443端口
# http请求重定向为https请求
# 有https证书使用这个
<VirtualHost *:80>
    ServerName godpython.com 
    Redirect permanent / https://www.godpython.com/ 
</VirtualHost>

# 没有https证书使用这个
# 处理godpython.com域名的访问
<VirtualHost *:80>
    ServerAdmin admin@godpython.com
    ServerName godpython.com
    ServerAlias  godpython.com
    DocumentRoot /var/www/html/godpython.com/public_html/ #网站目录
    ErrorLog /var/www/html/godpython.com/logs/error.log # 网站错误日志目录
    CustomLog /var/www/html/godpython.com/logs/access.log combined
</VirtualHost>


// 处理sincecode.com域名的访问
<VirtualHost *:80>
    ServerAdmin admin@sincecode.com
    ServerName sincecode.com
    ServerAlias www.sincecode.com
    DocumentRoot /var/www/html/sincecode.com/public_html/
    ErrorLog /var/www/html/sincecode.com/logs/error.log
    CustomLog /var/www/html/sincecode.com/logs/access.log combined
</VirtualHost>

监听https请求

首先要安装ssl支持: yum install
mod_ssl

在/etc/httpd/conf.d/目录下新建文件ssl.conf

LoadModule ssl_module modules/mod_ssl.so

Listen 443
<VirtualHost *:443>
     SSLEngine on
     SSLCertificateFile /etc/pki/tls/certs/godpython.com.crt # 域名crt证书
     SSLCertificateKeyFile /etc/pki/tls/private/godpython.com.key # 域名私钥
     SSLCACertificateFile  /etc/pki/tls/certs/godpython.com.ca.crt # 域名ca证书

    ServerAdmin admin@godpython.com
    ServerName godpython.com
    ServerAlias www.godpython.com
    DocumentRoot /var/www/html/godpython.com/public_html/
    ErrorLog /var/www/html/godpython.com/logs/error.log
    CustomLog /var/www/html/godpython.com/logs/access.log combined
</VirtualHost>

apache命令

安装

yum install httpd

启动

systemctl start httpd

关闭

systemctl stop httpd

重启

systemctl restart httpd

检测端口是否被监听

1.检查端口是否打开

输入命令:iptables -nvL

可以看到22,80,443端口已打开

2.借助端口扫描工具

原理:打开端口意味着防火墙允许访问,允许访问跟可以访问是两个概念,监听端口后才可以访问

端口扫描工具

参考

How to Install Apache on CentOS 7

SSL Certificates with Apache on CentOS 7

SSL服务检测

端口扫描工具

Leave a Reply

Your email address will not be published. Required fields are marked *