配置文件:/etc/httpd/conf/httpd.conf
DirectoryIndex index.html text.html #此处会优先读取前面一个文件。如果index文件不存在,就读取text文件。如果都没有,显示测试页
/etc/httpd/conf.d/*.conf conf.d目录下的所有conf文件
虚拟主机
基于主机名:
ServerName localhost.localdomain DocumentRoot /var/www/local
添加字段,控制文件访问权限:
创建2个用户(不是系统用户,是访问html的用户)
httpd-manual里面 Authentication and Authorization 中有
[root@localhost conf]# htpasswd -c /etc/httpd/.htpasswd user1New password: Re-type new password: Adding password for user user1[root@localhost conf]# htpasswd /etc/httpd/.htpasswd user2New password: Re-type new password: Adding password for user user2[root@localhost conf]# cat /etc/httpd/.htpasswd user1:$apr1$/HcTzDUm$16tL9pldhS4YV7i1E6GKU0user2:$apr1$qTaxMLFd$1YtqCEglB1e5lNyjUbuec1
ServerName localhost.localdomain DocumentRoot /var/www/local AuthType basic AuthName "Please Input Your Name&Passwd!" AuthUserFile /etc/httpd/.htpasswd Require user user1 #只有user1能访问 Require valid-user #.htpasswd中的用户都能访问
以索引的方式显示文件,并且可以显示链接文件
Mapping URLs to the Filesystem 手册中有
Options Indexes FollowSymlinks
Options -Indexes -FollowSymlinks #要关闭功能在前面加上-
添加IP限制
Access Control 手册
Order allow,deny ##后面的优先级高!!如果allow在后面,allow的优先级高 allow from 10.42.1.0/24 deny from 10.42.1.14
https
默认端口:443
安装包:mod_ssl
ssl的配置文件
/etc/httpd/conf.d/ssl.conf
Listen 443ServerName localhost.localdomain DocumentRoot /var/www/ssl SSLEngine on SSLProtocol all -SSLv2 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLCertificateFile /etc/pki/tls/certs/localhost.crt #服务端的证书 SSLCertificateKeyFile /etc/pki/tls/private/localhost.key #服务端的私钥 SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt #CA的证书
不要CA的证书,自己签名
[root@localhost certs]# lsca-bundle.crt localhost.crt Makefileca-bundle.trust.crt make-dummy-cert renew-dummy-cert[root@localhost certs]# pwd/etc/pki/tls/certs[root@localhost certs]# make chomper.crt
这个命令是指生成一个自签的证书,自己给自己签名。
用此种方式restart服务的时候需要输入私钥的密码。
生成一个私钥(需要输入密码),
生成一个公钥(证书)(需要输入私钥的密码)。
然后填写证书的信息(#主机名#)
Listen 443SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialogServerName www.chomper.com DocumentRoot /var/www/ssl SSLEngine on SSLProtocol all -SSLv2 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLCertificateFile /etc/pki/tls/certs/chomper.crt SSLCertificateKeyFile /etc/pki/tls/private/chomper.key
安装包 mod_wsgi
ServerName localhost.localdomain DocumentRoot /var/www/ssl WSGIScriptAlias / /var/www/ssl/webapp.wsgi
基于端口的虚拟主机:添加8899端口
Listen 8899ServerName www.chomper.com DocumentRoot /var/www/ssl
[root@localhost conf.d]# semanage port -l | grep httphttp_cache_port_t tcp 8080, 8118, 8123, 10001-10010http_cache_port_t udp 3130http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t tcp 5988pegasus_https_port_t tcp 5989[root@localhost conf.d]# semanage port -a -t http_port_t -p tcp 8899
[root@localhost conf.d]# semanage port -l | grep httphttp_cache_port_t tcp 8080, 8118, 8123, 10001-10010http_cache_port_t udp 3130http_port_t tcp 8899, 80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t tcp 5988pegasus_https_port_t tcp 5989